Method: PEROBS::Object#init_attr

Defined in:
lib/perobs/Object.rb

#init_attr(attr, val) ⇒ true|false

Initialize the specified attribute attr with the value val unless the attribute has been initialized already. Use this method in the class constructor to avoid overwriting values that have been set when the object was reconstructed from the store.

Parameters:

  • attr (Symbol)

    Name of the attribute

  • val (Any)

    Value to be set

Returns:

  • (true|false)

    True if the value was initialized, otherwise false.



93
94
95
96
97
98
99
100
# File 'lib/perobs/Object.rb', line 93

def init_attr(attr, val)
  if _all_attributes.include?(attr)
    _set(attr, val)
    return true
  end

  false
end