Skip to content

Instantly share code, notes, and snippets.

@brainopia
Created February 13, 2012 21:46
Show Gist options
  • Save brainopia/1820743 to your computer and use it in GitHub Desktop.
Save brainopia/1820743 to your computer and use it in GitHub Desktop.
# 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
# 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