Method: Cieloz::Helpers::ClassMethods#hattr_writer

Defined in:
lib/cieloz/helpers.rb

#hattr_writer(*attrs) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/cieloz/helpers.rb', line 4

def hattr_writer *attrs
  attrs.each { |attr|
    define_method "#{attr}=" do |value|
      if value.is_a? Hash
        name = attr.to_s.camelize
        cls = self.class.const_get name
        value = cls.new(value)
      end
      instance_variable_set "@#{attr}", value
      yield(value) if block_given?
    end
  }
end