Class: Binding
- Defined in:
- lib/core/facets/binding/op.rb,
lib/core/facets/binding/eval.rb,
lib/core/facets/binding/self.rb,
lib/core/facets/binding/caller.rb,
lib/core/facets/binding/defined.rb,
lib/core/facets/kernel/call_stack.rb,
lib/core/facets/binding/local_variables.rb
Instance Method Summary collapse
-
#[](x) ⇒ Object
Returns the value of some variable.
-
#[]=(l, v) ⇒ Object
Set the value of a local variable.
-
#__callee__ ⇒ Object
Retreive the current running method.
-
#__DIR__ ⇒ Object
Return the directory of the file in which the binding was created.
-
#__FILE__ ⇒ Object
Returns file name in which the binding was created.
-
#__LINE__ ⇒ Object
Return the line number on which the binding was created.
-
#__method__ ⇒ Object
Retreive the current running method.
-
#call_stack(level = 1) ⇒ Object
(also: #callstack)
Returns the call stack, in array format.
-
#caller(skip = 0) ⇒ Object
Returns the call stack, same format as Kernel#caller().
-
#defined?(x) ⇒ Boolean
Returns the nature of something within the context of the binding.
-
#eval(str) ⇒ Object
Evaluate a Ruby source code string (or block) in the binding context.
-
#local_variables ⇒ Object
Returns the local variables defined in the binding context:.
-
#self ⇒ Object
Returns self of the binding context.
Instance Method Details
#[](x) ⇒ Object
Returns the value of some variable.
a = 2
binding["a"] #=> 2
10 11 12 |
# File 'lib/core/facets/binding/op.rb', line 10 def []( x ) eval( x.to_s ) end |
#[]=(l, v) ⇒ Object
Set the value of a local variable.
binding["a"] = 4
a #=> 4
19 20 21 |
# File 'lib/core/facets/binding/op.rb', line 19 def []=( l, v ) eval( "lambda {|v| #{l} = v}").call( v ) end |
#__callee__ ⇒ Object
Retreive the current running method.
39 40 41 |
# File 'lib/core/facets/binding/caller.rb', line 39 def __callee__ Kernel.eval("__callee__", self) end |
#__DIR__ ⇒ Object
Return the directory of the file in which the binding was created.
27 28 29 |
# File 'lib/core/facets/binding/caller.rb', line 27 def __DIR__ File.dirname(self.__FILE__) end |
#__FILE__ ⇒ Object
Returns file name in which the binding was created.
21 22 23 |
# File 'lib/core/facets/binding/caller.rb', line 21 def __FILE__ Kernel.eval("__FILE__", self) end |
#__LINE__ ⇒ Object
Return the line number on which the binding was created.
15 16 17 |
# File 'lib/core/facets/binding/caller.rb', line 15 def __LINE__ Kernel.eval("__LINE__", self) end |
#__method__ ⇒ Object
Retreive the current running method.
33 34 35 |
# File 'lib/core/facets/binding/caller.rb', line 33 def __method__ Kernel.eval("__method__", self) end |
#call_stack(level = 1) ⇒ Object Also known as: callstack
Returns the call stack, in array format.
50 51 52 |
# File 'lib/core/facets/kernel/call_stack.rb', line 50 def call_stack(level=1) eval( "callstack( #{level} )" ) end |
#caller(skip = 0) ⇒ Object
Returns the call stack, same format as Kernel#caller()
9 10 11 |
# File 'lib/core/facets/binding/caller.rb', line 9 def caller( skip=0 ) eval("caller(#{skip})") end |
#defined?(x) ⇒ Boolean
Returns the nature of something within the context of the binding. Returns nil if that thing is not defined.
7 8 9 |
# File 'lib/core/facets/binding/defined.rb', line 7 def defined?(x) eval("defined? #{x}") end |
#eval(str) ⇒ Object
Evaluate a Ruby source code string (or block) in the binding context.
7 8 9 |
# File 'lib/core/facets/binding/eval.rb', line 7 def eval(str) Kernel.eval(str, self) end |
#local_variables ⇒ Object
Returns the local variables defined in the binding context:
a = 1
b = 2
binding.local_variables #=> [:a, :b]
12 13 14 |
# File 'lib/core/facets/binding/local_variables.rb', line 12 def local_variables() eval("local_variables") end |
#self ⇒ Object
Returns self of the binding context.
7 8 9 |
# File 'lib/core/facets/binding/self.rb', line 7 def self() @_self ||= eval("self") end |