Class: Class

Inherits:
Object
  • Object
show all
Defined in:
lib/at_protocol.rb

Instance Method Summary collapse

Instance Method Details

#dynamic_attr_reader(attr_name, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/at_protocol.rb', line 6

def dynamic_attr_reader(attr_name, &block)
  define_method(attr_name) do
    instance_variable = "@#{attr_name}"
    if instance_variable_defined?(instance_variable)
      instance_variable_get(instance_variable)
    else
      instance_variable_set(instance_variable, instance_eval(&block))
    end
  end
end