I have a Websocket server (using Rubame), and it handles server connections in block form:
server.run do |client|
# ...
end
The client sends a message (i.e. ping;end) to the server, then the server sends a message back (i.e. pong;end).
Instead of having my react-to-message code inside the block, creating a huge, ugly mess, I want to have it in a function:
def react(msg)
# ...
end
server.run do |client|
client.onmessage do |mess|
react(mess)
end
end
To send a message back to the client, I need to access the client variable passed to the server.run block, and it appears to not be accessible from within the method.
Is there a way to access the variables of a block from within a method which was called inside the block?