Module: ActiveObject::Range
- Defined in:
- lib/active_object/range.rb
Instance Method Summary collapse
- #combine(other) ⇒ Object
- #include_with_range?(other) ⇒ Boolean
- #overlaps?(other) ⇒ Boolean
- #sample ⇒ Object
- #shuffle ⇒ Object
- #within?(other) ⇒ Boolean
Instance Method Details
#combine(other) ⇒ Object
3 4 5 |
# File 'lib/active_object/range.rb', line 3 def combine(other) to_a.concat(other.to_a) end |
#include_with_range?(other) ⇒ Boolean
7 8 9 10 11 12 13 14 |
# File 'lib/active_object/range.rb', line 7 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
16 17 18 |
# File 'lib/active_object/range.rb', line 16 def overlaps?(other) cover?(other.first) || other.cover?(first) end |
#sample ⇒ Object
20 21 22 |
# File 'lib/active_object/range.rb', line 20 def sample to_a.sample end |
#shuffle ⇒ Object
24 25 26 |
# File 'lib/active_object/range.rb', line 24 def shuffle to_a.shuffle end |
#within?(other) ⇒ Boolean
28 29 30 |
# File 'lib/active_object/range.rb', line 28 def within?(other) cover?(other.first) && cover?(other.last) end |