Class: Range

Inherits:
Object show all
Defined in:
lib/lite/ruby/range.rb,
lib/lite/ruby/safe/range.rb

Instance Method Summary collapse

Instance Method Details

#boundsObject



5
6
7
# File 'lib/lite/ruby/range.rb', line 5

def bounds
  [self.begin, self.end]
end

#combine(other) ⇒ Object



9
10
11
# File 'lib/lite/ruby/range.rb', line 9

def combine(other)
  to_a.concat(other.to_a)
end

#include_with_range?(other) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/lite/ruby/range.rb', line 13

def include_with_range?(other)
  return include?(other) unless other.is_a?(Range)

  operator = exclude_end? && !other.exclude_end? ? :< : :<=
  include?(other.first) && other.last.send(operator, last)
end

#overlaps?(other) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/lite/ruby/safe/range.rb', line 5

def overlaps?(other)
  cover?(other.first) || other.cover?(first)
end

#sampleObject



20
21
22
# File 'lib/lite/ruby/range.rb', line 20

def sample
  to_a.sample
end

#shuffleObject



24
25
26
# File 'lib/lite/ruby/range.rb', line 24

def shuffle
  to_a.shuffle
end

#within?(other) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/lite/ruby/range.rb', line 28

def within?(other)
  cover?(other.first) && cover?(other.last)
end