Ruby Kernel

I'm playing with the RubyLanguage and I'm trying to override eval with my own eval. The PseudoCode is like this:

 def eval( params )
     doSomething
     old_eval( params )
     doSomethingElse
 end
How can I call the old eval from the new-one?

solution:

  alias :oldEval :eval
  def eval( code )
    puts "antes eval"
    oldEval( code )
    puts "despues eval"
  end

$a = "Hola mundo" eval "puts $a"


Eval is a method of the Kernel. You can access it with 'Kernel.eval'.

 def eval( params )
     puts 'before eval'
     Kernel.eval( params )
     puts 'after eval'
 end
In irb you can see a list of all the Kernel methods by invoking 'Kernel.methods.sort'.


CategoryRuby


EditText of this page (last edited September 15, 2005) or FindPage with title or text search