Class: Range
- Defined in:
- lib/lite/ruby/range.rb,
lib/lite/ruby/safe/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
8 9 10 |
# File 'lib/lite/ruby/range.rb', line 8 def combine(other) to_a.concat(other.to_a) end |
#include_with_range?(other) ⇒ Boolean
12 13 14 15 16 17 |
# File 'lib/lite/ruby/range.rb', line 12 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 |
#sample ⇒ Object
19 20 21 |
# File 'lib/lite/ruby/range.rb', line 19 def sample to_a.sample end |
#shuffle ⇒ Object
23 24 25 |
# File 'lib/lite/ruby/range.rb', line 23 def shuffle to_a.shuffle end |
#within?(other) ⇒ Boolean
27 28 29 |
# File 'lib/lite/ruby/range.rb', line 27 def within?(other) cover?(other.first) && cover?(other.last) end |