Created
January 29, 2009 10:29
-
-
Save levinalex/54492 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
#!/bin/bash | |
# | |
# some oddities with rails constant lookup | |
# | |
# "Foo::Bar" will return the toplevel constant "Bar" the first time it is referenced | |
# and fail the second time. | |
# | |
# (if Foo is a class instead of a module, the second call will print a warning and | |
# not raise a NameError) | |
# | |
RP=/tmp/tmp_rails | |
rm -rf $RP | |
rails $RP > /dev/null | |
cd $RP | |
cat <<EOF > app/models/bar.rb | |
class Bar | |
def self.hello | |
puts "should never be printed" | |
end | |
end | |
EOF | |
./script/console <<EOF | |
module Foo | |
end | |
Foo::Bar.hello # this returns the toplevel constant without printing a warning | |
Foo::Bar.hello # this does fail | |
EOF | |
# prints: | |
# | |
# >> Foo::Bar.hello | |
# should never be printed | |
# >> Foo::Bar.hello | |
# NameError: uninitialized constant Foo::Bar | |
# from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in `load_missing_constant' | |
# from /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:77:in `const_missing' | |
# from (irb):5 | |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment