Class: Range

Inherits:
Object show all
Defined in:
lib/ruco/core_ext/range.rb

Instance Method Summary collapse

Instance Method Details

#last_elementObject

(1..2).last_element == 2 (1…3).last_element == 2



9
10
11
# File 'lib/ruco/core_ext/range.rb', line 9

def last_element
  Dispel::Tools.last_element(self)
end

#move(n) ⇒ Object

(1..2).move(2) == (3..4)



14
15
16
17
18
19
20
# File 'lib/ruco/core_ext/range.rb', line 14

def move(n)
  if exclude_end?
    (first + n)...(last + n)
  else
    (first + n)..(last + n)
  end
end

#overlap?(other) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/ruco/core_ext/range.rb', line 3

def overlap?(other)
  (first <= other.last) and (other.first <= last)
end