当前位置: 代码迷 >> Ruby/Rails >> ruby深入研究三
  详细解决方案

ruby深入研究三

热度:123   发布时间:2016-04-29 02:20:03.0
ruby深入研究3

怎么绕过private方法的限制,直接调用private方法。

class AAA private  def private_method    puts 'this is private method'  end endend

?两种方式

1.用send

a = AAA.newa.send(:private_method)

?2.用重写方式

class XXX 《 AAA def private_method  super endendx = XXX.newx.private_method