Posted By

wdso on 06/22/09


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

wdso
webstic
jjuarez


Singleton classes


 / Published in: Ruby
 

  1. # How to define and use a singleton class
  2. # - modifies the class's class
  3. # - instance methods in the singleton class are class methods externally
  4.  
  5. class TheClass
  6. class << self
  7. def hello
  8. puts "hi"
  9. end
  10. end
  11. end
  12.  
  13. # invoke a class method
  14. TheClass.hello # hi

Report this snippet  

You need to login to post a comment.