Class: Hash

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

Overview

Note:

#to_proc was added to Hash in Ruby 2.7 so this patch is only applied for older versions of Ruby.

Extend core Hash object by adding #to_proc so hashes can be treated as functions of their keys.

Instance Method Summary collapse

Instance Method Details

#to_procProc

Return a proc that takes a key and returns the value associated with it or nil if the key is not present in the hash.

Returns:



10
11
12
13
14
# File 'lib/invokable/hash.rb', line 10

def to_proc
  lambda do |key|
    fetch(key) { nil }
  end
end