Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/core_ext/array.rb
Instance Method Summary collapse
-
#consolidate_ranges(method = :itself) ⇒ Array
Consolidate array of possibly overlapping ranges.
-
#constantize ⇒ Class, Module
Convert array of namespaces to constant.
Instance Method Details
#consolidate_ranges(method = :itself) ⇒ Array
Consolidate array of possibly overlapping ranges.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/core_ext/array.rb', line 21 def consolidate_ranges(method=:itself) uniq.sort_by { [_1.begin, _1.end] }.then do |ranges| consolidated, a = [], ranges.first Array(ranges[1..]).each do |b| if a.end.send(method) >= b.begin.send(method) # overlapping a = (a.begin..(a.end.send(method) > b.end.send(method) ? a.end : b.end)) else # not overlapping consolidated << a a = b end end consolidated << a end.compact end |
#constantize ⇒ Class, Module
Convert array of namespaces to constant.
9 10 11 |
# File 'lib/core_ext/array.rb', line 9 def constantize map(&:to_s).join('::').constantize end |