Class: Mixture::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/mixture/attribute.rb

Overview

An attribute for a mixture object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, list, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



9
10
11
12
13
# File 'lib/mixture/attribute.rb', line 9

def initialize(name, list, options = {})
  @name = name
  @list = list
  @options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/mixture/attribute.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/mixture/attribute.rb', line 7

def options
  @options
end

Instance Method Details

#getterObject



23
24
25
# File 'lib/mixture/attribute.rb', line 23

def getter
  @name
end

#ivarObject



19
20
21
# File 'lib/mixture/attribute.rb', line 19

def ivar
  @_ivar ||= :"@#{@name}"
end

#setterObject



27
28
29
# File 'lib/mixture/attribute.rb', line 27

def setter
  @_setter ||= :"#{@name}="
end

#update(value) ⇒ Object



15
16
17
# File 'lib/mixture/attribute.rb', line 15

def update(value)
  @list.callbacks[:update].inject(value) { |a, e| e.call(self, a) }
end