Module: Enumerable

Instance Method Summary collapse

Instance Method Details

#index_byObject

File activesupport/lib/active_support/core_ext/enumerable.rb, line 94



4
5
6
7
# File 'lib/core_ext/enumerable.rb', line 4

def index_by
  return to_enum :index_by unless block_given?
  Hash[map { |elem| [yield(elem), elem] }]
end

#uniq_byObject



9
10
11
12
# File 'lib/core_ext/enumerable.rb', line 9

def uniq_by
  h = {}
  inject([]) {|a,x| h[yield(x)] ||= a << x}
end