From: Luke Stark Date: 2006-10-02T23:49:57+09:00 Subject: Re: Creating dynamically named singleton methods. Syntax question. Jean, Hmm. This looks close, but the :test in your example can only be a variable that has been defined within the instance_eval...and I need to pass one from outside. The others run, but add the method to the class, rather than the instance of that class. I'm sure there's a simple way. I just can't see it. -L > -----Original Message----- > From: Jean Helou [mailto:jean.helou@gmail.com] > Sent: Monday, October 02, 2006 9:41 AM > To: ruby-talk ML > Subject: Re: Creating dynamically named singleton methods. Syntax > question. > > However this will define the given method for all new instances of > obj.class (MyThing in my example) which are created after this code is > executed, which is not what the OP seemed to want. > > jean > > ps: in my example :test can be a variable and String.to_sym is your > friend. > > On 10/2/06, Martin Coxall wrote: > > On 10/2/06, Jan Svitok wrote: > > > > > > On 10/2/06, Luke Stark wrote: > > > > You may create singleton methods like so: > > > > > > > > > > I'll have one more go. This time I'll get it right. ;p > > > > obj.class.instance_eval do > > define_method(:method_name) do |*args| > > # Method goes here > > end > > end > > > > N.B. this actually works this time, because I tried it. > > > > Regards, > > > > Martin > > > >