From: Joel VanderWerf Date: 2003-03-18T17:19:43+09:00 Subject: Re: Substitution in a string in a string Tim Bates wrote: > I am using eval to dynamically define a method, and at some point, I want to > do this: > raise "Invalid type: #{val}" > Except that this is inside an eval'd string, and so #{val} gets evaluated the > first time, and at this point val doesn't exist. I've tried all sorts of > things like > raise "Invalid type: #{"#{val}"}" > but none of them quite do what I want. I eventually settled for > raise "Invalid type: " + val.to_s > but it still raises the question, how do you force a #{...} not to be > evaluated? > > Tim Bates It's so obvious, it's easy to miss: eval %{ def greet name puts "Hello, \#{name}" end } greet "Fred"