In ruby you use the dot to call a method, or in other words, to send a method to the object treated.
"100".to_i
We are sending to the object "100" the message to_i
When we do:
puts "hello"
The method puts, to which object is applied?
I thought this:
self.puts "hello"
Where self would be main, like the environment where you are now, the irb console for example.
But it throws an error.
Traceback (most recent call last):
2: from /Users/albert/.rbenv/versions/2.5.0/bin/irb:11:in `<main>'
1: from (irb):17
NoMethodError (private method `puts' called for main:Object)
Why is this wrong? Where is the method puts applied?
UPDATE: Ruby 2.7 allows calling private methods with self. This feature was requested and discussed at 1 and 2.