Module: Enumerable

Defined in:
lib/map_hash.rb

Instance Method Summary collapse

Instance Method Details

#map_hash(&block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/map_hash.rb', line 2

def map_hash(&block)
  inject({}) do |memo, *args|
    results = block.call(*args)
    unless results.nil?
      k, v = results
      memo[k]=v
    end
    memo
  end
end

#slice_hashObject



13
14
15
16
17
# File 'lib/map_hash.rb', line 13

def slice_hash
  hash={}
  each_slice(2) { |k,v| hash[k]=v }
  hash
end