module Enumerable
Public Instance Methods
duplicates()
click to toggle source
Returns the first-appearing duplicate of each element, preserving order of appearance.
@example
%w[a a b c c b a d].duplicates # == ["a", "c", "b"]
@return [Enumerable]
# File lib/casual_support/enumerable/duplicates.rb, line 10 def duplicates seen = Hash.new(0) self.select{|element| (seen[element] += 1) == 2 } end
index_to() { |k))| ... }
click to toggle source
Creates a Hash
using the Enumerable's elements as keys, and using the given block to compute an associated value for each key.
@example
cache = id_list.index_to{|id| find_by_id(id) }
@yield [key] @yieldparam key [Object] @yieldreturn [Object] value @return [Hash{key => value}]
# File lib/casual_support/enumerable/index_to.rb, line 15 def index_to() self.reduce({}){|h, k| h.put!(k, (yield k)) } end