Module: Quant::Attributes::ClassMethods

Defined in:
lib/quant/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, key: nil, default: nil) ⇒ Object

Define an attribute for the class that can optionally be serialized. Works much like an attr_accessor does, but also manages serialization for #to_h and #to_json methods.

An attribute will result in a same-named instance on the class when it is instantiated and it will set a default value if one is provided.

Parameters:

  • name (Symbol)

    The name of the attribute and it’s accessor methods

  • key (String) (defaults to: nil)

    The key to use when serializing the attribute

  • default (Object) (defaults to: nil)

    The default value for the attribute



196
197
198
# File 'lib/quant/attributes.rb', line 196

def attribute(name, key: nil, default: nil)
  Attributes.register(self, name, key, default)
end