Reputation: 4349
I am new to ruby development and I am making a simple chat server encrypted over TLS.
I have managed to get the basic server running however I now want to add special properties to each of the connected clients (username, etc.)
I have this class which I plan to use for each client that connects:
class Client < OpenSSL::SSL::SSLSocket
attr_accessor :username
...
end
I need to get a Client
object from the OpenSSL::SSL::SSLServer.accept
function in order to set the username attribute. I am used to C type languages where casting would do the trick but Google has told me that this is not the case in Ruby.
What is the Ruby way of doing this?
Upvotes: 0
Views: 55
Reputation: 531
There are essentially 2 ways to solve your problem:
Upvotes: 0
Reputation: 16730
You don't need casting in Ruby. It's a dynamic language. So what matters is if the object knows how to respond to a message (method).
Upvotes: 2