Module: AutoAttr

Defined in:
lib/autoattr.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/autoattr.rb', line 2

def method_missing(method, *args, &block)
  if method.to_s.include? "="
    attr = method.to_s.sub('=','')
    self.class.class_eval { attr_accessor attr.to_sym }
    instance_variable_set "@#{attr.to_s}", args[0]
  else
    super(method, *args, &block)
  end
end