Sha256: 1f1898f4cc04f142b45c6139149a38e7f9a828d31a0863022de36c607fc67fe8

Contents?: true

Size: 579 Bytes

Versions: 4

Compression:

Stored size: 579 Bytes

Contents

# frozen_string_literal: true

class Range

  def bounds
    [self.begin, self.end]
  end

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

  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

  def sample
    to_a.sample
  end

  def shuffle
    to_a.shuffle
  end

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

end

require 'lite/ruby/safe/range' unless defined?(ActiveSupport)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lite-ruby-2.3.0 lib/lite/ruby/range.rb
lite-ruby-2.2.0 lib/lite/ruby/range.rb
lite-ruby-2.1.0 lib/lite/ruby/range.rb
lite-ruby-2.0.7 lib/lite/ruby/range.rb