Sha256: 10e0f03854455fbc56970ae77c58ec208ad545f663d65e1b631b525b03d13697
Contents?: true
Size: 543 Bytes
Versions: 16
Compression:
Stored size: 543 Bytes
Contents
class Hash # Constructs a Proc object from a hash such # that the parameter of the Proc is assigned # the hash keys as attributes. # # h = { :a => 1 } # p = h.to_proc # o = OpenStruct.new # p.call(o) # o.a #=> 1 # def to_proc lambda do |o| self.each do |k,v| ke = "#{k}=" o.__send__(ke, v) end end end def to_proc_with_reponse lambda do |o| self.each do |k,v| ke = "#{k}=" o.__send__(ke, v) if respond_to?(ke) end end end end
Version data entries
16 entries across 16 versions & 1 rubygems