From: Wai-Sun Chia Date: 2001-09-04T02:13:52+09:00 Subject: [ruby-talk:20792] Indirect eval doesn't work?? Dear Rubyists, I have this Ruby code: ================== foo.rb ==================== #!/usr/bin/ruby code = "" File.open ("foo.tmpl" ,"r") { |fd| fd.each { |line| code << line } } class Foo end puts Foo.public_instance_methods.inspect print code eval code puts Foo.public_instance_methods.inspect ============================================== And this data file: ================= foo.tmpl =================== class Foo bar = 9999 def foo_#{bar} puts "this is in foo" end end ============================================== When I run it, I get: [] class Foo bar = 9999 def foo_#{bar} puts "this is in foo" end end ["foo_"] Why is it that #{bar} doesn't get extrapolated? Basically what I'm doing is just trying to define a method dynamically based on some string.... -- Wai-Sun "Squidster" Chia RHCE/Professional Services Linux/Unix/Web Developer