From: Johann Hibschman Date: 2001-02-28T04:40:03+09:00 Subject: [ruby-talk:11711] Re: automatic method creation Dave Thomas writes: > Ruby has a set of general delimited thingies (strings, regexps, > etc). The %{...} form is a double quoted string. The delimiters can be > either matching brackets, braces, parentheses, and '<' '>', or they can > be any arbitrary character: Oh, I see. I missed the fact that %{ ... } was the same as %Q{ ... }. Here's my final toy version. I'm just pleased that I finally found a use for a singleton class. They still confuse me a bit, though. class SillyMath end class << SillyMath def make_square(method) class_eval %{ def #{method.to_s + "_2"} (x) #{method}(x)**2 end } end end class SillyMath def times3 (x) x*3 end make_square(:times3) def plus1 (x) x+1 end make_square(:plus1) end Thanks for the help, this has been fun. --J -- Johann Hibschman johann@physics.berkeley.edu