- class PT
- private
- def private_method
- puts "private method executed!"
- end
- end
- p = PT.new
- begin
- p.private_method
- rescue NoMethodError
- puts "call Private method error!"
- end
- PT.new.method(:private_method).call
最后执行结果如下:
>ruby C:/magic.rb
call Private method error!
private method executed!
最新评论