Method: RubyRanges::Array#+
- Defined in:
- lib/ruby_ranges/array.rb
#+(object) ⇒ Object
Takes either a Range or Array of Ranges
RubyRanges::Array.new(1..4, 8..11) + RubyRanges::Array.new(3..6, 7..9) =>
RubyRanges::Array.new(1..6, 7..9)
RubyRanges::Array.new(1..4, 8..11) + (3..9) => 1..9
This method will “flatten” any RubyRanges::Array which compasses the smallest to the largest. It will also compress an ranges which overlap.
33 34 35 36 37 |
# File 'lib/ruby_ranges/array.rb', line 33 def +(object) raise "Expecting RubyRanges::Array or Range, but was #{object.class} : #{object.inspect}" unless object.is_a?(Range) || object.is_a?(Array) array_of_ranges = Array.new((object.is_a?(Range) ? (self.old_plus([object])) : super(object))) array_of_ranges.flatten_ranges end |