From: Dave Thomas Date: 2002-05-02T06:37:07+09:00 Subject: Re: is this FAQ material? -> adding instance methods to an object.... patrick-may@monmouth.com (Patrick May) writes: > I was trying to add instance methods to an object. I figured this out > by looking at some library source, but I had problems finding this > info on ruby talk or in the FAQ. > I didn't see it when I looked at the FAQ at > http://www.rubycentral.com/faq/rubyfaq.html 8.4 What is a singleton method? A singleton method is an instance method associated with one specific object. You create a singleton method by including the object in the definition: class Foo end foo = Foo.new bar = Foo.new def foo.hello puts "Hello" end foo.hello bar.hello Produces: Hello prog.rb:10: undefined method `hello' for # (NameError) Singleton methods are useful when you want to add a method to an object and creating a new subclass is not appropriate. I agree the title of this entry isn't the most helpful in the world :) Dave