Module: Hahamut::Support::Attributes::ClassMethods

Defined in:
lib/hahamut/support/attributes.rb

Overview

Define attribute class

Instance Method Summary collapse

Instance Method Details

#attribute(name, type) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/hahamut/support/attributes.rb', line 15

def attribute(name, type)
  name = name.to_sym
  klass = Attribute.const_get(type.to_s.capitalize)

  define_method name do
    @attributes[name]&.value
  end

  define_method "#{name}=" do |value|
    @attributes ||= {}
    @attributes[name] = klass.new(value)
  end
end