lib/blobject.rb in blobject-0.4.0 vs lib/blobject.rb in blobject-0.4.1

- old
+ new

@@ -221,11 +221,11 @@ setter_name = (name.to_s + '=').to_sym unless methods.include? setter_name self.send :define_method, setter_name do |value| begin - value = self.class.send(:__blobjectify__, value) if value.is_a?(Hash) or value.is_a?(Array) + value = self.class.send(:__blobjectify__, value) @hash[name] = value rescue => ex __tag_and_raise__(ex) end @store_in_parent.call unless @store_in_parent.nil? @@ -235,12 +235,21 @@ unless methods.include? name self.send :define_method, name do value = @hash[name] - if value.nil? + if value.nil? && !frozen? value = self.class.new - @hash[name] = value unless frozen? + + # close the scope for storing call chain + parent = self + + store_in_parent = lambda do + parent.send "#{name}=", value + value.send :remove_instance_variable, :@store_in_parent + end + + value.instance_variable_set :@store_in_parent, store_in_parent end value end end