Module: Enumerable
- Includes:
- JishoSort::Sortable
- Defined in:
- lib/jisho_sort/enumerable.rb
Instance Method Summary collapse
-
#jisho_sort {|a, b| ... } ⇒ Array<String>
Sorts an array of strings using the Japanese pronunciation (dictionary)order.
-
#jisho_sort_by {|item| ... } ⇒ Array
Sorts the elements of the enumerable based on the japanese pronunciation of the strings returned by the given block.
Methods included from JishoSort::Sortable
Instance Method Details
#jisho_sort {|a, b| ... } ⇒ Array<String>
Sorts an array of strings using the Japanese pronunciation (dictionary)order. If a block is given, it sorts using the provided block.
14 15 16 17 18 19 20 |
# File 'lib/jisho_sort/enumerable.rb', line 14 def jisho_sort(&block) raise ArgumentError if block.nil? && !all? { |item| item.instance_of?(String) } return sort { |a, b| a.compare_by_furigana(b) } if block.nil? sort(&block) end |
#jisho_sort_by {|item| ... } ⇒ Array
Sorts the elements of the enumerable based on the japanese pronunciation of the strings returned by the given block.
29 30 31 32 33 |
# File 'lib/jisho_sort/enumerable.rb', line 29 def jisho_sort_by raise ArgumentError unless all? { |item| yield(item).instance_of?(String) } sort_by{ |item| yield(item).furigana } end |