Issue
Hi everyone's try to use a split method in a module but I can't, the terminal give me this error: undefined method `split' for :"set algo":Symbol (NoMethodError)
class Server
def initialize(port,ip)
@server = TCPServer.open(ip,port)
@connections = Hash.new
@clients = Hash.new
@connections[:server] = @server
@connections[:clients] = @clients
run
split
end
def run
loop{
Thread.start(@server.accept) do | client |
# for each user connected and accepted by server, it will create a new thread object
# and which pass the connected client as an instance to the block
request = client.gets.chomp.to_sym
dev = request.split(" ")
client.puts dev[0]
#if dev[0] == "set"
# client.puts "OPERACION VALIDA"
#else
# client.puts "OPERACION INVALIDA "
# Thread.kill self
#end
end
}.join
end
end
Server.new(3000, "localhost")
Solution
Replace:
request = client.gets.chomp.to_sym
With:
request = client.gets.chomp
Calling to_sym
converts the string from gets
/chomp
to a symbol which doesn't implement split
.
Answered By - Stefan Answer Checked By - Cary Denson (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.