Module: Unnatural::Fast
- Defined in:
- lib/unnatural/fast.rb
Defined Under Namespace
Modules: Ext
Class Method Summary collapse
Class Method Details
.compare(a, b) ⇒ Object
12 13 14 |
# File 'lib/unnatural/fast.rb', line 12 def self.compare(a, b) Ext.compare(a, a.size, b, b.size) end |
.sort(enumerable) ⇒ Object
16 17 18 |
# File 'lib/unnatural/fast.rb', line 16 def self.sort(enumerable) enumerable.sort { |a, b| compare(a, b) } end |
.sort_by(enumerable) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/unnatural/fast.rb', line 20 def self.sort_by(enumerable) raise ArgumentError, 'Block expected but none given' unless block_given? enumerable .map { |e| [(yield e), e] } .sort { |a, b| compare(a.first, b.first) } .map { |ary| ary[1] } end |