Sha256: 78f245eeee10cb77a9975a0fbc4bedc33d132947619a2c0f2e7e01e3a4a7b09b
Contents?: true
Size: 689 Bytes
Versions: 6
Compression:
Stored size: 689 Bytes
Contents
require 'facets/core/hash/to_h' require 'facets/core/proc/to_h' module Kernel # Similiar to #set_with, but ignores missing setters. def populate( data=nil, &yld ) if data data.to_h.each do |k,v| send( "#{k}=", v ) rescue nil end end if yld yld.to_h.each do |k,v| send( "#{k}=", v ) rescue nil end end # If the context of the error could be known # this could be used instead of converting the # block to a hash. #begin # yield self #rescue NoMethodError => e # if e.context == self and e.name.to_s =~ /=$/ # resume # else # raise e # end #end self end end
Version data entries
6 entries across 6 versions & 1 rubygems