Method: PEROBS::Object#attr_init
- Defined in:
- lib/perobs/Object.rb
#attr_init(attr, val = nil, &block) ⇒ Object
Use this method to initialize persistent attributes in the restore() method that have not yet been initialized. This is the case when the object was saved with an earlier version of the program that did not yet have the instance variable. If you want to assign another PEROBS object to the variable you should use the block variant to avoid unnecessary creation of PEROBS object that later need to be collected again.
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/perobs/Object.rb', line 111 def attr_init(attr, val = nil, &block) if _all_attributes.include?(attr) unless instance_variable_defined?('@' + attr.to_s) _set(attr, block_given? ? yield : val) end return true else raise ArgumentError, "'#{attr}' is not a defined persistent " + "attribute of class #{self.class}" end false end |