Module: ActsAsKaltura::TwoWayAttrAccessor::ClassMethods

Defined in:
lib/acts_as_kaltura/two_way_attr_accessor.rb

Instance Method Summary collapse

Instance Method Details

#dual_attr_accessor(*var_names) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/acts_as_kaltura/two_way_attr_accessor.rb', line 8

def dual_attr_accessor(*var_names)
  var_names.each do |m|
    m           = m.to_s
    setter_proc = lambda do |value|
      self.instance_variable_set :"@#{m.underscore}", value
    end
    self.send :define_method, :"#{m}=", setter_proc
    self.send :define_method, :"#{m.underscore}=", setter_proc

    getter_proc = lambda { self.instance_variable_get :"@#{m.underscore}" }
    self.send :define_method, m.to_sym, getter_proc
    self.send :define_method, :"#{m.underscore}", getter_proc
  end
end