Skip to content

Instantly share code, notes, and snippets.

@kachick
Created September 2, 2013 11:31
Show Gist options
  • Save kachick/6411912 to your computer and use it in GitHub Desktop.
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
$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