sort-by-alphabet 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/enumerable.rb +10 -2
  2. metadata +1 -1
data/lib/enumerable.rb CHANGED
@@ -1,11 +1,19 @@
1
1
  module Enumerable
2
2
 
3
3
  def sort_by_alphabet(alphabet)
4
- sort{|a, b| a.compare_by_alphabet_sensitive(b, alphabet)}
4
+ if block_given?
5
+ sort{|a, b| yield(a).to_s.compare_by_alphabet_sensitive(yield(b).to_s, alphabet)}
6
+ else
7
+ sort{|a, b| a.to_s.compare_by_alphabet_sensitive(b.to_s, alphabet)}
8
+ end
5
9
  end
6
10
 
7
11
  def isort_by_alphabet(alphabet)
8
- sort{|a, b| a.compare_by_alphabet_insensitive(b, alphabet)}
12
+ if block_given?
13
+ sort{|a, b| yield(a).to_s.compare_by_alphabet_insensitive(yield(b).to_s, alphabet)}
14
+ else
15
+ sort{|a, b| a.to_s.compare_by_alphabet_insensitive(b.to_s, alphabet)}
16
+ end
9
17
  end
10
18
 
11
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sort-by-alphabet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frantisek Havluj