I often see ::
and .
.
This is a clarification that the notation changes due to the difference in method call.
python
class User
def method
puts "Hello"
end
end
python
> user = User.new
> user.method
Hello
=> nil
python
class User
def method
puts "Welcome"
end
end
python
> user = User.new
> user::method
Welcome
=> nil
The difference between dot notation and colon notation is whether you can call a constant.
notation | Method call | Calling a constant |
---|---|---|
Dot notation | ○ | × |
Colon notation | ○ | ○ |
python
require 'uri'
require 'net/http'
url = URI.parse("http://yahoo.co.jp")
http = Net::HTTP.start(url.host, url.port)
python
> document = http.get(url.path)
> puts document.body
#View document
In this way, the colon notation allows you to access items in a class or module in another specified file.
Recommended Posts