Module: ActiveObject::Range

Defined in:
lib/active_object/range.rb

Instance Method Summary collapse

Instance Method Details

#combine(other) ⇒ Object



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

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

#include_with_range?(other) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'lib/active_object/range.rb', line 10

def include_with_range?(other)
  if other.is_a?(Range)
    operator = exclude_end? && !other.exclude_end? ? :< : :<=
    include?(other.first) && other.last.send(operator, last)
  else
    include?(other)
  end
end

#overlaps?(other) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/active_object/range.rb', line 19

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

#sampleObject



23
24
25
# File 'lib/active_object/range.rb', line 23

def sample
  to_a.sample
end

#shuffleObject



27
28
29
# File 'lib/active_object/range.rb', line 27

def shuffle
  to_a.shuffle
end

#within?(other) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/active_object/range.rb', line 31

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