From: 7stud -- Date: 2009-09-04T09:19:15+09:00 Subject: Re: Is Passing a Binding with Parameters Possible? John Sikora wrote: > > Obviuosly, this requires a code block for 'called_method'. In the actual > code, whenever eval is used, parameters are always present. Code blocks > are optional. So when a code block is not needed, the empty code block > has to be included. > > No big deal, but it would be nice to be able to use the parameters to > pass the binding How about: def called_method(*parameters, &code_block) if block_given? #do something elsif b = parameters[-1] params = parameters[0..-2] params.each do |param| eval(param, b) end end end def calling_method a = 3 string_to_evaluate = 'puts a' called_method(string_to_evaluate, binding) end calling_method # => 3 -- Posted via http://www.ruby-forum.com/.