Define a singleton method, one that is tied to a single object : Singletons « Design Patterns « Ruby






Define a singleton method, one that is tied to a single object


class Singleton
end

s = Singleton.new
def s.handle
  puts "I'm a singleton method!"
end

s.handle # => I'm a singleton method!

 








Related examples in the same category

1.define class methods by using a class within a class's singleton class like the code
2.Singleton a class
3.Classes as Singletons
4.Modules as Singletons
5.include Singleton