Class: UltraMarathon::SubContext
- Includes:
- Logging
- Defined in:
- lib/ultra_marathon/sub_context.rb
Instance Attribute Summary collapse
-
#__context ⇒ Object
readonly
Returns the value of attribute __context.
Instance Method Summary collapse
-
#initialize(context, &run_block) ⇒ self
constructor
Initializes the SubContext and defines #call as the passed in run_block.
-
#method_missing(method, *args, &block) ⇒ Object
If the original context responds, including private methods, delegate to it.
Methods included from Logging
Constructor Details
#initialize(context, &run_block) ⇒ self
Initializes the SubContext and defines #call as the passed in run_block
11 12 13 14 15 16 |
# File 'lib/ultra_marathon/sub_context.rb', line 11 def initialize(context, &run_block) @__context = context # Ruby cannot marshal procs or lambdas, so we need to define a method. # Binding to self allows us to intercept logging calls. define_singleton_method(:call, run_block.bind(self)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
If the original context responds, including private methods, delegate to it
27 28 29 30 31 32 33 34 |
# File 'lib/ultra_marathon/sub_context.rb', line 27 def method_missing(method, *args, &block) if __context.respond_to?(method, true) __context.send(method, *args, &block) else raise NoMethodError.new("undefined local variable or method `#{method.to_s}' for #{__context.class.name}") end end |
Instance Attribute Details
#__context ⇒ Object (readonly)
Returns the value of attribute __context.
4 5 6 |
# File 'lib/ultra_marathon/sub_context.rb', line 4 def __context @__context end |