Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Module
- def singleton_object
- if singleton_class?
- ObjectSpace.each_object(Object).find do |o|
- begin
- (o.singleton_class == self)
- rescue TypeError
- false
- end
- end
- end
- end
- end
- class Example
- PARENTS = []
- class << PARENTS
- FATHER = :father
- MOTHER = :mother
- singleton_object.push(FATHER, MOTHER)
- end
- end
- p Example::PARENTS
- # [:father, :mother]
- p Example.constants
- # [:PARENTS]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement