Intercept reads/writes to underlying TCPSocket

I’m thinking of playing around with raw bytes SSLSocket sends into underlying TCPSocket. In order to do that, I decided to patch TCPSocket methods in the way shown below. However, the overridden methods were not invoked.

class TCPSocket
    def write(*args)
        p "write"
        super *args
    def read(*args)
        p "read"
        super *args

Tcp_socket = '', 443
ssl_context =
socket =, ssl_context)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs