Understanding private methods in Ruby

前端 未结 7 1235
终归单人心
终归单人心 2020-11-29 00:01
class Example
 private
 def example_test
  puts \'Hello\'
 end
end

e = Example.new
e.example_test

This of course will not work, because we specifi

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 00:42

    IIRC, private methods allow only implicit receiver (which is always self, of course).

提交回复
热议问题