Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p Module.constants.length # => 88
- $snapshot1 = Module.constants
- class A
- NAME=:abc
- $snapshot2 = Module.constants
- p $snapshot2.length # => 90
- p $snapshot2 - $snapshot1 # => ["A", "NAME"]
- end
- p Module.constants.length # => 89
- p Module.constants - $snapshot1 # => ["A"]
- p A.constants # => ["NAME"]
- p A.class # => Class
- p A.class.ancestors # => [Class, Module, Object, Kernel]
- # No argument: same class method as in 1.8:
- Module.constants # ==> All constants
- # One argument: uses the instance method:
- Module.constants(true) # ==> Constants of Module (and included modules)
- Module.constants(false) # ==> Constants of Module (only).
- class << Module
- define_method :constants_of_module, Module.instance_method(:constants)
- end
- # Now use this new class method:
- class Module
- COOL = 42
- end
- Module.constants.include?("COOL") # ==> false, as you mention
- Module.constants_of_module # ==> ["COOL"], the result you want
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement