Created
September 2, 2013 11:31
-
-
Save kachick/6411912 to your computer and use it in GitHub Desktop.
定数の参照 - 前にruby-listへ投稿したけど特に反応が得られなかったもの http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/48791
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
$VERBOSE = true | |
class Super | |
class << self | |
CONS = :Singleton | |
end | |
CONS = :Super | |
end | |
class Sub < Super | |
CONS = :Sub | |
end | |
class Sub | |
class << self | |
# 1 | |
p CONS #=> :Sub | |
p const_get(:CONS) #=> :Singleton | |
end | |
end | |
class << Sub | |
# 2 | |
p CONS #=> :Singleton | |
p const_get(:CONS) #=> :Singleton | |
end | |
class Sub | |
class Nested < Super | |
# 3 | |
p CONS #=> :Sub | |
p const_get(:CONS) #=> :Super | |
end | |
end | |
class Sub::Nested | |
# 4 | |
p CONS #=> :Super | |
p const_get(:CONS) #=> :Super | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment