Module: Alf::Support::Scope::OwnMethods
- Defined in:
- lib/alf-support/alf/support/scope.rb
Instance Method Summary collapse
-
#__branch(arg) ⇒ Object
Branches this scope with ‘arg`, returning a child scope of this one.
-
#__eval_binding ⇒ Binding
Returns the binding to use for an evaluation.
-
#evaluate(expr = nil, path = nil, line = nil, &bl) ⇒ Object
Evaluates an expression in the scope.
-
#lambda(*args, &block) ⇒ Object
Delegated to ::Kernel.
-
#method_missing(name, *args, &bl) ⇒ Object
Delegated to parent if any.
-
#respond_to?(name, include_private = false) ⇒ Boolean
Returns true if the decorated tuple has ‘name` as key.
-
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
Returns true.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &bl) ⇒ Object
Delegated to parent if any.
49 50 51 52 53 54 |
# File 'lib/alf-support/alf/support/scope.rb', line 49 def method_missing(name, *args, &bl) @parent ? @parent.__send__(name, *args, &bl) : super rescue NoMethodError => ex name = ex.[/`(.*?)'/, 1] ::Kernel.raise NoMethodError, "Not found `#{name}` on #{self}" end |
Instance Method Details
#__branch(arg) ⇒ Object
Branches this scope with ‘arg`, returning a child scope of this one.
64 65 66 67 68 69 70 |
# File 'lib/alf-support/alf/support/scope.rb', line 64 def __branch(arg) case arg when ::Hash then TupleScope.new(arg, [], self) else Kernel::raise NotImplementedError, "Unable to branch with `#{arg}`" end end |
#__eval_binding ⇒ Binding
Returns the binding to use for an evaluation
59 60 61 |
# File 'lib/alf-support/alf/support/scope.rb', line 59 def __eval_binding RUBY_VERSION < "1.9" ? binding : ::Kernel.binding end |
#evaluate(expr = nil, path = nil, line = nil, &bl) ⇒ Object
Evaluates an expression in the scope.
29 30 31 32 |
# File 'lib/alf-support/alf/support/scope.rb', line 29 def evaluate(expr = nil, path=nil, line=nil, &bl) return instance_exec(&bl) if bl ::Kernel.eval expr, __eval_binding, *[path, line].compact end |
#lambda(*args, &block) ⇒ Object
Delegated to ::Kernel
21 22 23 |
# File 'lib/alf-support/alf/support/scope.rb', line 21 def lambda(*args, &block) ::Kernel.lambda(*args, &block) end |
#respond_to?(name, include_private = false) ⇒ Boolean
Returns true if the decorated tuple has ‘name` as key.
37 38 39 40 41 |
# File 'lib/alf-support/alf/support/scope.rb', line 37 def respond_to?(name, include_private = false) return true if @extensions.any?{|m| m.method_defined?(name) } return true if BasicObject.method_defined?(name) @parent && @parent.respond_to?(name) end |
#respond_to_missing?(symbol, include_private = false) ⇒ Boolean
Returns true.
44 45 46 |
# File 'lib/alf-support/alf/support/scope.rb', line 44 def respond_to_missing?(symbol, include_private = false) @parent && @parent.respond_to?(symbol, include_private) end |