From: Philip Mak Date: 2002-07-11T02:49:32+09:00 Subject: Thanks (Re: Accessing caller's binding?) On Wed, Jul 10, 2002 at 10:03:36AM +0900, Ned Konz wrote: -snip- Thanks! That code solved the puzzle for me and taught me the following: 1. Use instance_eval, allowing me to pass 'self' instead of having to type 'binding()', or 'eval' a block of returned code (which is dangerous now that I think about it, if the variable names contain unsafe characters). 2. Even if I can't define a variable inside eval(), I can still define a function with the same name that returns the value I want. The way #2 works seems a bit awkward, but it works. So, here's what I'm doing now: class CGI def export(target, vars) vars.each do |var| target.instance_eval("def self.#{var}; $cgi['#{var}'][0]; end") end end end $cgi.export(self, %w(name phone email)) (I was able to remove the _mycgi stuff because in my application, there's a global variable called $cgi that is initialized to CGI.new at the beginning of every new HTTP request.) Thanks again.