Method: Transproc::ClassTransformations.set_ivars

Defined in:
lib/transproc/class.rb

.set_ivars(ivar_hash, klass) ⇒ Object

Set instance variables from the hash argument (key/value pairs) on the object

Examples:

Transproc(:set_ivars, Object)[name: 'Jane', age: 25]
# => #<Object:0x007f411d06a210 @name="Jane", @age=25>

Parameters:

  • (Object)

Returns:

  • (Object)


44
45
46
47
48
49
50
# File 'lib/transproc/class.rb', line 44

def self.set_ivars(ivar_hash, klass)
  object = klass.allocate
  ivar_hash.each do |ivar_name, ivar_value|
    object.instance_variable_set("@#{ivar_name}", ivar_value)
  end
  object
end