17
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rubyの::について

Posted at

Rubyのコロンを使用した書き方(「::」)について、分かりやすいと思ったコードを備忘録的に残しておきます。
コロンを使用した書き方では、メソッドの呼び出し以外に定数の呼び出しにも利用され、下記は定数の扱い例です。

sample.rb

A = "::A"
class Foo
A = "Foo::A"
class Bar
A = "Foo::Bar::A"
p A # => "Foo::Bar::A"
p Foo::A # => "Foo::A"
p ::A # => "::A"
end
end


上記サンプルコードは次のサイトから頂きました。
[stack overflow](https://ja.stackoverflow.com/questions/2446/ruby-%E3%81%A7%E3%82%AF%E3%83%A9%E3%82%B9%E5%90%8D%E3%81%AE%E5%85%88%E9%A0%AD%E3%81%AB-%E3%81%8C%E3%81%A4%E3%81%8F%E3%81%A8%E3%81%8D%E3%81%AE%E6%84%8F%E5%91%B3%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6)
17
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?