Module: Eco::Language::Methods::DslAble
- Defined in:
- lib/eco/language/methods/dsl_able.rb
Overview
Note:
- If a method is missing on the evaluation object, it will re-try it on on the block context.
- Override behaviour: the above gives precedence to methods defined in the context of the object that evaluates, over those in the block context.
Adds #evaluate, which will run &block where DslAble has been included.
Instance Method Summary collapse
-
#evaluate(*args, **kargs, &block) ⇒ Object
It runs the
blockwithin this object context. -
#method_missing(method, *args, **kargs, &block) ⇒ Object
When it's the case, redirect to the original
evaluatecaller. -
#respond_to_missing?(name, include_private = false) ⇒ Boolean
This allows to capture a method using
namemethod.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kargs, &block) ⇒ Object
When it's the case, redirect to the original evaluate caller
25 26 27 28 29 |
# File 'lib/eco/language/methods/dsl_able.rb', line 25 def method_missing(method, *args, **kargs, &block) super unless @self_before_evaluate @self_before_evaluate.send(method, *args, **kargs, &block) end |
Instance Method Details
#evaluate(*args, **kargs, &block) ⇒ Object
Note:
if the object misses any method, redirects the method to the original evaluate caller.
It runs the block within this object context
13 14 15 16 17 18 19 20 21 |
# File 'lib/eco/language/methods/dsl_able.rb', line 13 def evaluate(*args, **kargs, &block) return unless block_given? @self_before_evaluate = eval('self', block.binding, __FILE__, __LINE__) instance_exec(*args, **kargs, &block).tap do @self_before_evaluate = nil end end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Note:
that for a Dsl this is not necessary
This allows to capture a method using name method.
33 34 35 |
# File 'lib/eco/language/methods/dsl_able.rb', line 33 def respond_to_missing?(name, include_private = false) super end |