Module: Unnatural::Split
- Defined in:
- lib/unnatural/split.rb
Constant Summary collapse
- SPLITTER =
/(?<=\d)(?=\D)|(?<=\D)(?=\d)/
- PRED =
['0'.ord.pred.chr].freeze
Class Method Summary collapse
- .compare(a, b) ⇒ Object
- .sort(enumerable) ⇒ Object
- .sort_by(enumerable) ⇒ Object
- .split(string) ⇒ Object
Class Method Details
.compare(a, b) ⇒ Object
15 16 17 |
# File 'lib/unnatural/split.rb', line 15 def self.compare(a, b) split(a) <=> split(b) end |
.sort(enumerable) ⇒ Object
6 7 8 |
# File 'lib/unnatural/split.rb', line 6 def self.sort(enumerable) enumerable.sort_by { |s| split(s) } end |
.sort_by(enumerable) ⇒ Object
10 11 12 13 |
# File 'lib/unnatural/split.rb', line 10 def self.sort_by(enumerable) raise ArgumentError, "Block expected but none given" unless block_given? enumerable.sort_by { |s| split(yield s) } end |