Sha256: 7326d63177efcddb5b5b81d67df24172caa7f54fb4187a132c0a425040d825e9

Contents?: true

Size: 635 Bytes

Versions: 2

Compression:

Stored size: 635 Bytes

Contents

module ActiveObject::Range

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

  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

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

  def sample
    to_a.sample
  end

  def shuffle
    to_a.shuffle
  end

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

end

Range.send(:include, ActiveObject::Range) if ActiveObject.configuration.autoload_range

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_object-3.1.0 lib/active_object/range.rb
active_object-3.0.0 lib/active_object/range.rb