Created
June 26, 2013 22:54
-
-
Save jordansissel/5872482 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Foo | |
class Error < StandardError; end | |
end | |
module Foo | |
class Baz | |
def initialize | |
puts Error | |
end | |
end | |
end | |
class Foo::Bar | |
def initialize | |
puts Error | |
end | |
end | |
# Works: | |
puts Foo::Baz.new | |
# Fails: uninitialized constant Foo::Bar::Error | |
puts Foo::Bar.new |
Sorry but that's not obvious, a lot of people think the second construct is a shortcut for the first. Including me-five-minutes-ago. Principle of least surprise anyone ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Duh. Duh? Duh!
"class Foo::Bar; end" is in the scope of your file. Why? Because you never opened another scope.
"class Baz; end" is in the scope of the Foo module. Why? Because you opened it with "module Foo".
Where is the WTF?