From: dblack@... Date: 2007-08-02T10:49:31+09:00 Subject: Re: defining methods dynamically? Hi -- On Thu, 2 Aug 2007, Kenneth McDonald wrote: > Having looked through the Class and Method rdoc, and the Reflection section > of Pickaxe, and still not seeing anything (even though it was probably right > in front of my nose), I'm forced to fall on the mercy of strangers and > ask...how does one add a method to a class while the program is running? There's actually no other way to do it :-) But I think what you're looking for is #define_method, which lets you define methods with dynamically-determined names and also gives you a way to flatten the variable scope of a method definition. For example: str = "greet" c = Class.new c.class_eval { define_method(str) { puts "Hello" } } c.new.greet # Hello David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)