新手问题 能 overwrite 模块的方法吗

williamherry · August 01, 2012 · Last by williamherry replied at August 02, 2012 · 2416 hits

我想复写 Net::SSH.start,当连接或者认证出错是打印错误而不退出,使用

class Net::SSH
  def conn(options)
    ...
    self.start(options)
  end
end

这样写提示它是一个模块,模块的方法怎么复写,或者这样的需求怎么实现

猴子补丁法:

def Net::SSH.start
end

怎么我的报错

test.rb:6: syntax error, unexpected '.', expecting '\n' or ';'
def Net::SSH.start
             ^
test.rb:19: syntax error, unexpected kEND, expecting $end

@hooopo 我还是多还一点 ruby 再写吧,谢谢你的回答

找到了,原来是

module Net::SSH
  def start
...

#2 楼 @williamherry 是我误导你了。。start 是实例方法

@hooopo 没事,我把问题没有说清楚

You need to Sign in before reply, if you don't have an account, please Sign up first.