From: ts Date: 2002-09-24T00:27:16+09:00 Subject: Re: String[#.]interpolate (was Re: String interpolation at will?) >>>>> "H" == Hal E Fulton writes: H> Can you show me an example of something H> that fails? pigeon% cat b.rb #!/usr/bin/ruby class String def String.interp=(blk) @@interp = blk end end # Back to top-level scope String.interp = (Proc.new do |s| __str = s.dup __str.gsub!(/"/,'\"') eval('"' + __str + '"') end) # Now define the methods class String def String.interpolate(str) @@interp.call(str) end def interpolate @@interp.call(self) end end def aa str = <<'END' He said, "I am the #{alpha} and the #{omega}." Have a nice day. END puts str alpha = "WALRUS" omega = "WEATHER IS FINE" str2 = str.interpolate puts str2 str3 = String.interpolate(str) puts str3 end alpha = "walrus" omega = "weather is fine" aa pigeon% pigeon% b.rb He said, "I am the #{alpha} and the #{omega}." Have a nice day. He said, "I am the walrus and the weather is fine." Have a nice day. He said, "I am the walrus and the weather is fine." Have a nice day. pigeon% Guy Decoux