看板 Ruby 關於我們 聯絡資訊
class A def a puts "A exe" end def b puts "B exe" end end class B < A def a #HOW TO CALL A.b ?? super puts "A2 exe" end def b super puts "B2 exe" end end a=B.new a.a 新手,正在邊看書邊練習 想請問這種狀況要怎麼解決?有辦法呼叫的到嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.38.65.154
hSATAC:self.class.superclass.instance_method(:b).bind(self) 12/19 00:11
hSATAC:.call 12/19 00:11
mars90226:從沒想過這問題,google一下好像只有一些hack的解法 12/19 00:12
mars90226:就如樓上所說了,或者是用alias_method之類的方式 12/19 00:12
hSATAC:method swizzling 12/19 00:15
LaPass:感謝 m(_ _)m 12/19 00:29
LaPass:主要還是因為在其他語言有看過這東東,在學的時候就會想, 12/19 00:29
LaPass:在Ruby上是怎麼處理 12/19 00:30
jokester:http://stackoverflow.com/questions/8616442/ 有一些 12/19 14:02