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

#combine(other) ⇒ Object



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

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

#include_with_range?(other) ⇒ Boolean



10
11
12
13
14
15
# File 'lib/lite/ruby/range.rb', line 10

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



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

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

#sampleObject



17
18
19
# File 'lib/lite/ruby/range.rb', line 17

def sample
  to_a.sample
end

#shuffleObject



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

def shuffle
  to_a.shuffle
end

#within?(other) ⇒ Boolean



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

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