From: Sascha Ebach Date: 2005-08-05T09:15:03+09:00 Subject: Need help with with Binding.of_caller Hi, (hoping that Florian is reading) I am just in the process of patching ri18n[1] interpolation functionality. Here is what I a trying to do: ri18n offers a way to interpolate strings. This is for translation purposes. The current version of the interpolation method looks like this: class String def interpolate(caller) caller.instance_eval('"' << self.gsub('"', '\"') << '"') end ... end original version is here: http://svn.berlios.de/viewcvs/ri18n/trunk/lib/ri18n/standard_exts.rb?view=markup This will correctly interpolate the following: @color = 'red' _i('#{@color} whine') but not this: color = 'red' _i('#{color} whine') So I thought I might try to use the Binding.of_caller technique. I came as far as this: class String def interpolate(caller) # the param is not needed anymore Binding.of_caller do |binding| eval('"' << self.gsub('"', '\"') << '"', binding) end end ... end which will do exactly the opposite. Now I am able to eval local variables, but not the instance vars. this doesn't work: @color = 'red' _i('#{@color} whine') but this does: color = 'red' _i('#{color} whine') What do I need to do to capture the whole environment of the originating _i() call. Is it at all possible? Sascha Ebach [1] http://ri18n.berlios.de/