Skip to content

Instantly share code, notes, and snippets.

@stevenharman
Last active January 13, 2022 20:08
Show Gist options
  • Save stevenharman/2968308 to your computer and use it in GitHub Desktop.
Save stevenharman/2968308 to your computer and use it in GitHub Desktop.
ProTip™ on Constant Scoping and Resolution in Ruby: One of these is not like the other.
module Root
FOO = 'Ayyyy!'
end
module Root::NotNested
def self.speak
puts FOO
end
end
module Root
module Nested
def self.speak
puts FOO
end
end
end
Root::FOO #=> 'Ayyyy!'
Root::NotNested.speak #=> NameError: uninitialized constant Root::NotNested::FOO
Root::Nested.speak #=> 'Ayyyy!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment