module Nuggets::Array::LimitMixin

Public Instance Methods

between(min, max, uniq = true)
Alias for: limit
cap(max) click to toggle source
# File lib/nuggets/array/limit_mixin.rb, line 45
def cap(max)
  if max.respond_to?(:begin)
    min, max = max.begin, max.end
    map { |item| item.limit(min, max) }
  else
    map { |item| item.max(max) }
  end
end
limit(min, max) → anArray click to toggle source

Returns a new array of all distinct values in array limited to min and max (cf. Numeric#limit). If uniq is true, resulting duplicates will be removed.

# File lib/nuggets/array/limit_mixin.rb, line 37
def limit(min, max, uniq = true)
  limited = cap(min..max)
  limited.uniq! if uniq
  limited
end
Also aliased as: between