From: Tim Hunter Date: 2006-03-26T09:03:53+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, 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. > > Best regards, > > ---------------------------- > Eust�quio "TaQ" Rangel > eustaquiorangel@yahoo.com > http://beam.to/taq > Usu�rio GNU/Linux no. 224050 > > Hmmm...you can use Object#extend to add the instance methods from a module. Is that what you're looking for?