Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/core_augmentations/Array/index_by.rb

Instance Method Summary collapse

Instance Method Details

#index_by(position) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/core_augmentations/Array/index_by.rb', line 2

def index_by(position)
  index = {}
  self.each do |entry|
    if entry.kind_of?(Array) || entry.kind_of?(Hash)
      raise "No Entry: #{position} in entry." unless entry[position]
      raise "Duplicate Index: #{entry[position]}" if index[entry[position]]
      index[entry[position]] = entry
    end
  end

  return index
end