Return to Snippet

Revision: 15035
at June 22, 2009 05:01 by wdso


Initial Code
# How to define and use a singleton class
# - modifies the class's class
# - instance methods in the singleton class are class methods externally

class TheClass
  class << self
    def hello
      puts "hi"
    end
  end
end

# invoke a class method
TheClass.hello            # hi

Initial URL

                                

Initial Description

                                

Initial Title
Singleton classes

Initial Tags

                                

Initial Language
Ruby