From: eric.promislow@... Date: 2005-07-30T10:36:04+09:00 Subject: Better way to extend Kernel#eval -- can't require 'openssl' This program doesn't work (ruby 1.8.2 (2004-12-25) [i386-mswin32]): # ==== 8-< ===== module Kernel alias_method :old_eval, :eval def eval(*args) res = old_eval(*args) print "**** eval(#{args}) => #{res}\n" return res end end require 'openssl' print "Done\n" # ==== 8-< ===== If I run it I get this output: eval_wrapper.rb:4:in `eval': (eval):1:in `eval': uninitialized constant Kernel:: Cipher (NameError) from c:/ruby/lib/ruby/site_ruby/1.8/openssl/cipher.rb:24:in `old_eval' from eval_wrapper.rb:4:in `eval' from c:/ruby/lib/ruby/site_ruby/1.8/openssl/cipher.rb:24 from c:/ruby/lib/ruby/site_ruby/1.8/openssl/cipher.rb:23:in `each' from c:/ruby/lib/ruby/site_ruby/1.8/openssl/cipher.rb:23 from c:/ruby/lib/ruby/site_ruby/1.8/openssl.rb:20:in `require' from c:/ruby/lib/ruby/site_ruby/1.8/openssl.rb:20 from eval_wrapper.rb:10:in `require' from eval_wrapper.rb:10 Here's the problematic code from openssl: module OpenSSL module Cipher %w(AES Cast5 BF DES Idea RC2 RC4 RC5).each{|cipher| eval(<<-EOD) class #{cipher} < OpenSSL::Cipher::Cipher def initialize(*args) args = args.join('-') if args.size == 0 super(\"#{cipher}\") else super(\"#{cipher}-#\{args\}\") end end end EOD } If I change the first line in the eval block from "... < Cipher" to "< OpenSSL::Cipher::Cipher" it works. The problem is obviously that the hook causes the eval block to be eval'ed in the hook's binding, not the original binding. What's the best way to get the binding I need? Yes, I have a trace-function, but I don't see an obvious event that tells me the eval hook is about to be called. Thanks, Eric