Where is TCPSocket.puts implemented? Can you provide a description of
how the implementation location could be found without prior knowledge?
I’ve looked in socket/TCPSocket.c but the puts method isn’t defined
there.
I’m trying to implement a basic TCP server using Ruby’s IPSocket as a
learning exercise. The Socket class doesn’t have a public ‘puts’ method
like TCPSocket and I would like to know what is happening here.
Thanks - I see that rb_io_puts is defined in io.c. Maybe I should have
asked: where is it visible that TCP inherits ‘puts’ from IO, but
IPSocket does not?
My confusion is coming from the fact that TCPSocket and IPSocket both
inherit from IO so they should have the same public methods, right?
Also, I would expect to see any differences between TCPSocket and
IPSocket encapsulated in tcpsocket.c. Maybe something like this:
rb_define_method(rb_cTCPSocket, “puts”, rb_io_puts, -1);
However, tcpsocket.c does not assign rb_io_puts to TCPSocket. Am I
misunderstanding something?
For future readers: my confusion was stemming from the response type of
Socket.accept (returns an array) vs. TCPServer.accept (returns
TCPSocket).
Socket does in fact have a public method ‘puts’ - in my case, I was
trying to call ‘puts’ on the array returned by Socket.accept which is
itself not a socket.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.