class Mixture::Attribute
An attribute for a mixture object.
Attributes
The name of the attribute.
@return [Symbol]
The options for the attribute. This is mainly used for coercion and validation.
@return [Hash]
Public Class Methods
Initialize the attribute.
@param name [Symbol] The name of the attribute. @param list [AttributeList] The attribute list this attribute is
a part of.
@param options [Hash] The optiosn for the attribute.
# File lib/mixture/attribute.rb, line 24 def initialize(name, list, options = {}) @name = name @list = list @options = options end
Public Instance Methods
@!attribute [r] getter The getter method for this attribute.
@example Retrieve the getter.
attribute.getter # => :name
@return [Symbol]
# File lib/mixture/attribute.rb, line 56 def getter @name end
@!attribute [r] ivar The instance variable for this attribute.
@example Retrieve the instance variable.
attribute.ivar # => :@name
@return [Symbol]
# File lib/mixture/attribute.rb, line 46 def ivar @_ivar ||= :"@#{@name}" end
@!attribute [r] setter The setter method for this attribute.
@example Retrieve the setter.
attribute.setter # :name=
@return [Symbol]
# File lib/mixture/attribute.rb, line 66 def setter @_setter ||= :"#{@name}=" end
Update the attribute with the given value. It runs the value through the callbacks, and returns a new value given by the callbacks.
@param value [Object] The new value. @return [Object] The new new value.
# File lib/mixture/attribute.rb, line 36 def update(value) @list.callbacks[:update].inject(value) { |a, e| e.call(self, a) } end