Class: DynamicBinding::LookupStack
- Inherits:
-
Object
- Object
- DynamicBinding::LookupStack
- Defined in:
- lib/alephant/logger/dynamic_binding.rb
Instance Method Summary collapse
-
#initialize(bindings = []) ⇒ LookupStack
constructor
A new instance of LookupStack.
- #method_missing(m, *args) ⇒ Object
- #run_proc(p, *args) ⇒ Object
Constructor Details
#initialize(bindings = []) ⇒ LookupStack
Returns a new instance of LookupStack.
3 4 5 |
# File 'lib/alephant/logger/dynamic_binding.rb', line 3 def initialize(bindings = []) @bindings = bindings end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/alephant/logger/dynamic_binding.rb', line 7 def method_missing(m, *args) @bindings.reverse_each do |bind| begin method = eval('method(%s)' % m.inspect, bind) rescue NameError else return method.call(*args) end begin value = eval(m.to_s, bind) return value rescue NameError end end raise NoMethodError, 'No such variable or method: %s' % m end |
Instance Method Details
#run_proc(p, *args) ⇒ Object
24 25 26 |
# File 'lib/alephant/logger/dynamic_binding.rb', line 24 def run_proc(p, *args) instance_exec(*args, &p) end |