Class: IRB::Driver::Socket

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

Class Attribute Summary collapse

Class Method Summary collapse

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.



23
24
25
26
27
# File 'lib/irb/driver/socket.rb', line 23

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

Class Attribute Details

.instanceObject (readonly)

Returns the value of attribute instance.



8
9
10
# File 'lib/irb/driver/socket.rb', line 8

def instance
  @instance
end

Class Method Details

.run(object, binding) ⇒ Object



10
11
12
13
# File 'lib/irb/driver/socket.rb', line 10

def run(object, binding)
  @instance = new(object, binding)
  @instance.run
end

Instance Method Details

#runObject

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



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/irb/driver/socket.rb', line 30

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