Module: Gemmy::Patches::ObjectPatch::InstanceMethods::ObjectState
- Defined in:
- lib/gemmy/patches/object_patch.rb
Instance Method Summary collapse
-
#object_state(data = nil) ⇒ Object
obj.object_state(:a=>3, :b=>4) obj.a #=> 3 obj.b #=> 4.
Instance Method Details
#object_state(data = nil) ⇒ Object
obj.object_state(:a=>3, :b=>4) obj.a #=> 3 obj.b #=> 4
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gemmy/patches/object_patch.rb', line 41 def object_state(data=nil) if data instance_variables.each do |iv| name = iv.to_s.sub(/^[@]/, '').to_sym instance_variable_set(iv, data[name]) end else data = {} instance_variables.each do |iv| name = iv.to_s.sub(/^[@]/, '').to_sym data[name] = instance_variable_get(iv) end data end end |