If `self` is always the implied receiver in Ruby, why doesn't `self.puts` work?

后端 未结 4 1735
野性不改
野性不改 2021-01-12 19:22

In Ruby, my understanding is that self is the implied receiver for any bare method call. However:

~: irb
>> puts \"foo\"
foo
=> nil
>         


        
4条回答
  •  耶瑟儿~
    2021-01-12 19:55

    You can't access private methods in ruby using the self. syntax, or generally speaking using any receiver (something in front of the .). That is only possible for protected methods.

提交回复
热议问题