Sha256: fd9371289241224bf6ca281a10c165474965d537c65f5110351b6ae8b32c3f6b

Contents?: true

Size: 717 Bytes

Versions: 20

Compression:

Stored size: 717 Bytes

Contents

# frozen_string_literal: true

module ActiveObject
  module 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
end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
active_object-5.7.0 lib/active_object/range.rb
active_object-5.6.0 lib/active_object/range.rb
active_object-5.5.3 lib/active_object/range.rb
active_object-5.5.2 lib/active_object/range.rb
active_object-5.5.1 lib/active_object/range.rb
active_object-5.5.0 lib/active_object/range.rb
active_object-5.4.0 lib/active_object/range.rb
active_object-5.3.1 lib/active_object/range.rb
active_object-5.3.0 lib/active_object/range.rb
active_object-5.2.5 lib/active_object/range.rb
active_object-5.2.4 lib/active_object/range.rb
active_object-5.2.3 lib/active_object/range.rb
active_object-5.2.2 lib/active_object/range.rb
active_object-5.2.1 lib/active_object/range.rb
active_object-5.2.0 lib/active_object/range.rb
active_object-5.1.2 lib/active_object/range.rb
active_object-5.1.1 lib/active_object/range.rb
active_object-5.1.0 lib/active_object/range.rb
active_object-5.0.2 lib/active_object/range.rb
active_object-5.0.1 lib/active_object/range.rb