Skip to content

Instantly share code, notes, and snippets.

@cainlevy
Created January 10, 2013 17:51
Show Gist options
  • Save cainlevy/4504210 to your computer and use it in GitHub Desktop.
Save cainlevy/4504210 to your computer and use it in GitHub Desktop.
ruby constant lookups
#!/usr/bin/env ruby
X = 'hello'
module A
X = 'world'
end
module A::B
def self.tst
puts "nesting: " + Module.nesting.map(&:name).join(' > ')
puts "value: " + X
end
end
module A
module C
def self.tst
puts "nesting: " + Module.nesting.map(&:name).join(' > ')
puts "value: " + X
end
end
end
A::B.tst
print "\n"
A::C.tst
=begin OUTPUT
nesting: A::B
value: hello
nesting: A::C > A
value: world
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment