Module: Spyke::AttributeAssignment::ClassMethods

Defined in:
lib/spyke/attribute_assignment.rb

Instance Method Summary collapse

Instance Method Details

#attributes(*names) ⇒ Object

By adding instance methods via an included module, they become overridable with “super”. thepugautomatic.com/2013/07/dsom/



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/spyke/attribute_assignment.rb', line 16

def attributes(*names)
  unless instance_variable_defined?(:@spyke_instance_method_container)
    @spyke_instance_method_container = Module.new
    include @spyke_instance_method_container
  end

  @spyke_instance_method_container.module_eval do
    names.each do |name|
      define_method(name) do
        attribute(name)
      end

      define_method(:"#{name}=") do |value|
        set_attribute(name, value)
      end
    end
  end
end