Advertisement
Guest User

Untitled

a guest
Feb 12th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.48 KB | None | 0 0
  1. class Module
  2.   def singleton_object
  3.     if singleton_class?
  4.       ObjectSpace.each_object(Object).find do |o|
  5.         begin
  6.           (o.singleton_class == self)
  7.         rescue TypeError
  8.           false
  9.         end
  10.       end
  11.     end
  12.   end
  13. end
  14.  
  15. class Example
  16.   PARENTS = []
  17.   class << PARENTS
  18.     FATHER = :father
  19.     MOTHER = :mother
  20.     singleton_object.push(FATHER, MOTHER)
  21.   end
  22. end
  23.  
  24. p Example::PARENTS
  25. # [:father, :mother]
  26. p Example.constants
  27. # [:PARENTS]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement