Method: Taupe::Accessorized::ClassMethods#stacked_accessor

Defined in:
lib/taupe/core.rb

#stacked_accessor(*names) ⇒ Object

Note:

The getter is “_name_stack” instead of “name”

Define stacked accessor. It can be set several times.

Examples:

stacked_accessor :name, { type; String, null; false }

Parameters:

  • names (Array)

    Set of names, and a hash of values



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/taupe/core.rb', line 40

def stacked_accessor(*names)
  names.each do |name|
    define_method name do |*data|
      stack = instance_variable_get("@_#{name}_stack".to_sym) || {}
      stack[data[0]] = data[1]
      instance_variable_set "@_#{name}_stack".to_sym, stack
    end
    define_method "_#{name}_stack" do
      instance_variable_get "@_#{name}_stack".to_sym
    end
  end
end