From: Robert Klemme Date: 2006-03-26T19:53:54+09:00 Subject: Re: Object methods Eustaquio Rangel de Oliveira J wrote: > Hello, Robert! > >> I'm not sure what exactly you're after. Do you mean >> class String >> def says >> print "s says: ", self, "\n" >> end >> end >> ? > > Not really, I want to create a new method on the > object, after it's created, but not on the class. As > the previous example of > > s = "Testing" > class < def says > print "s says: ", self, "\n" > end > end > > where it creates the method (and all that metaclass > stuff). > > At this point just, just s have the "says" method, not > the class String or any other String object that was > created or will be created. Using > > s.class.class_eval %q(def x.says() puts "x says:"+self > end) > > have the same effect, This doesn't work for me. You define a method "say" for an instance "x" in the scope of the class. You probably want something else. > but what I like to know if there > is another way to do that. I mean, create a method on > a specific object (on this case, just "s"), not on the > class. def s.says puts "I say " + self end It would certainly help if you tell us what problem you are trying to solve. Cheers robert