I would really like to see the block version, that's what I ever missed in eval.
But that's probably not easy with the interpreter, because of two bindings inclolved, the argument and the one from the block.
Also on my wishlist would be Kernel.caller to return bindings.
Useful for debugging, I think and would allow some hacking with dynamic scoping of variables (method_missing looks up the caller chain and returns a local variable, can be abused, but sometimes useful like in emacs).
@batkins you can use the HTML pre tags for code formatting
-- Matthias Georgi
My rcr.rb file contains:
# By default class Binding has no methods at all !
class Binding
# Evaluate a Ruby source code string in the binding context
def eval( str )
Kernel.eval( str, self)
end
# Returns the self in the binding context
def self()
eval( "self")
end
# Returns the local variables defined in the binding context
def local_variables()
eval( "local_variables")
end
# Returns the Method that was active, if any, when the binding was created
#def method() ...???...
# Returns the Proc that was active, if any, when the binding was created
#def proc() ... ??? ...
# Returns the call stack, same format as Kernel##caller()
def caller( skip = 0 )
eval( "caller( #{skip})")
end
# Returns the value of some variable
def []( x )
eval( x.to_s())
end
# Set the value of some lvalue
def []=( l, v )
eval( "proc {|v| #{l} = v").call( v)
end
# Returns the nature of something, nil if that thing is not defined.
def defined?( x )
eval( "defined? #{x}")
end
end
-- JeanHuguesRobert
I would really like to see the block version, that's what I ever missed in eval.
But that's probably not easy with the interpreter, because of two bindings inclolved, the argument and the one from the block.
Also on my wishlist would be Kernel.caller to return bindings.
Useful for debugging, I think and would allow some hacking with dynamic scoping of variables (method_missing looks up the caller chain and returns a local variable, can be abused, but sometimes useful like in emacs).
@batkins you can use the HTML pre tags for code formatting
-- Matthias Georgi
My rcr.rb file contains:
-- JeanHuguesRobert