Class: IRB::Driver::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/irb/driver/socket.rb

Instance Method Summary collapse

Constructor Details

#initialize(object, binding, host = '127.0.0.1', port = 7829) ⇒ Socket

Initializes with the object and binding that each new connection will get as Context. The binding is shared, so local variables will stay around. The benefit of this is that a socket based irb session is most probably used to debug a running application in development. In this scenario it could be beneficial to keep local vars in between sessions.

TODO see if that actually works out ok.



14
15
16
17
18
# File 'lib/irb/driver/socket.rb', line 14

def initialize(object, binding, host = '127.0.0.1', port = 7829)
  @object, @binding = object, binding
  @host, @port = host, port
  @server = TCPServer.new(host, port)
end

Instance Method Details

#runObject

TODO libedit doesn’t use the right input and output, so we can’t use Readline for now!!



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/irb/driver/socket.rb', line 21

def run
  $stderr.puts "[!] Running IRB server on #{@host}:#{@port}"
  loop do
    connection = @server.accept
    Thread.new do
      # assign driver with connection to current thread and start runloop
      IRB::Driver.current = TTY.new(connection, connection)
      irb(@object, @binding)
      connection.close
    end
  end
end