Class: At::MethodToInstanceVariableProxy
Instance Method Summary collapse
-
#initialize(parent) ⇒ MethodToInstanceVariableProxy
constructor
A new instance of MethodToInstanceVariableProxy.
- #method_missing(meth, *args) ⇒ Object
Constructor Details
#initialize(parent) ⇒ MethodToInstanceVariableProxy
Returns a new instance of MethodToInstanceVariableProxy.
9 10 11 |
# File 'lib/at.rb', line 9 def initialize(parent) @parent = parent end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/at.rb', line 13 def method_missing(meth, *args) @parent.instance_eval do if match = meth.to_s.match(/(.*)\=$/) value = args.length == 1 ? args.first : args instance_variable_set("@#{match[1]}", value) else if args.empty? instance_variable_get("@#{meth}") else value = args.length == 1 ? args.first : args instance_variable_set("@#{meth}", value) end end end end |