module Nuggets::Array::LimitMixin
Public Instance Methods
cap(max)
click to toggle source
# File lib/nuggets/array/limit_mixin.rb 45 def cap(max) 46 if max.respond_to?(:begin) 47 min, max = max.begin, max.end 48 map { |item| item.limit(min, max) } 49 else 50 map { |item| item.max(max) } 51 end 52 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 37 def limit(min, max, uniq = true) 38 limited = cap(min..max) 39 limited.uniq! if uniq 40 limited 41 end
Also aliased as: between