class Hash
Extend core Hash
object by adding {to_proc} so hashes can be treated as functions of their keys.
@note {to_proc} was added to Hash
in Ruby 2.7 so this patch is only applied for older versions of Ruby.
Public Instance Methods
to_proc()
click to toggle source
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.
@return [Proc]
# File lib/invokable/hash.rb, line 10 def to_proc lambda do |key| fetch(key) { nil } end end