Created
February 13, 2012 21:46
-
-
Save brainopia/1820743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Module.constants allows you to check all available at point of call constants | |
module Bar | |
AvailableUnderNamespace = :constant | |
end | |
class Foo | |
include Bar | |
p Module.constants.include?(:AvailableUnderNamespace) # => true | |
end | |
# Check constants under the Module | |
Module::FooBar = :constant | |
p Module.instance_method(:constants).bind(Module).call # => [:FooBar] | |
# or simpler way | |
p Module.constants false # => [:FooBar] | |
# http://bugs.ruby-lang.org/issues/5887 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://apidock.com/ruby/Module/nesting/class | |
module Foo | |
module Bar | |
p Module.nesting # =>[Foo::Bar, Foo] | |
end | |
end | |
# http://coderrr.wordpress.com/2009/05/18/dynamically-adding-a-constant-nesting-in-ruby-1-9/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment