我正在尝试split
在 Ruby 中使用,但出现此错误:
`importantFuncs':为 nil:NilClass (NoMethodError) 调用私有方法`split'
我尝试添加require String
and require string
,但都没有工作。
require 'socket'
class IRC
def initialize(ip, port)
@s = TCPSocket.new(ip, port)
print 'Now connected to ip ', ip, ' at port ', port, "\n"
end
def getPacket()
line = @s.gets
puts line
end
def closeConnection()
@s.close
end
def sendPacket(packet)
@s.write(packet)
end
def importantFuncs(nick)
sendPacket("NICK #{nick}")
z = getPacket
@m = z.split(':')
sendPacket("NICK #{nick}")
end
#def joinChannel(
end
ip = '127.0.0.1'
port = '6667'
i = IRC.new(ip, port)
i.importantFuncs('test')
i.getPacket