Class: Workhorse::ScopedEnv
- Inherits:
-
Object
- Object
- Workhorse::ScopedEnv
- Defined in:
- lib/workhorse/scoped_env.rb
Instance Method Summary collapse
-
#initialize(delegation_object, methods, backup_binding = nil) ⇒ ScopedEnv
constructor
A new instance of ScopedEnv.
- #method_missing(symbol, *args, &block) ⇒ Object
- #respond_to_missing?(symbol, include_private = false) ⇒ Boolean
Constructor Details
#initialize(delegation_object, methods, backup_binding = nil) ⇒ ScopedEnv
Returns a new instance of ScopedEnv.
3 4 5 6 7 |
# File 'lib/workhorse/scoped_env.rb', line 3 def initialize(delegation_object, methods, backup_binding = nil) @delegation_object = delegation_object @methods = methods @backup_binding = backup_binding end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/workhorse/scoped_env.rb', line 9 def method_missing(symbol, *args, &block) if @methods.include?(symbol) @delegation_object.send(symbol, *args, &block) elsif @backup_binding.try(:respond_to?, symbol) @backup_binding.send(symbol, *args, &block) else super end end |
Instance Method Details
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
19 20 21 |
# File 'lib/workhorse/scoped_env.rb', line 19 def respond_to_missing?(symbol, include_private = false) @methods.include?(symbol) || super end |