Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/hash.rb

Instance Method Summary collapse

Instance Method Details

#hash_select(&block) ⇒ Object

in Ruby < 1.9 select returns an array not a hash…



3
4
5
6
7
8
9
# File 'lib/hash.rb', line 3

def hash_select(&block)
  inject({}) do |selected_hash, param|
    key, value = param
    selected_hash[key] = value if block.call(key, value)
    selected_hash
  end
end