Class: PryBot::StringIOProxy

Inherits:
Object
  • Object
show all
Includes:
DRb::DRbUndumped
Defined in:
lib/io-string-proxy.rb

Overview

Class used to wrap modules so that they can be sent through DRb. This will mostly be used for Readline.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ StringIOProxy

Returns a new instance of StringIOProxy.



8
9
10
11
12
# File 'lib/io-string-proxy.rb', line 8

def initialize(obj)
  @stdout = $stdout
  @stdin = $stdin
  @obj = obj
end

Instance Attribute Details

#completion_procObject

Returns the value of attribute completion_proc.



20
21
22
# File 'lib/io-string-proxy.rb', line 20

def completion_proc
  @completion_proc
end

#objObject

Returns the value of attribute obj.



7
8
9
# File 'lib/io-string-proxy.rb', line 7

def obj
  @obj
end

Instance Method Details

#<<(data) ⇒ Object



48
49
50
51
# File 'lib/io-string-proxy.rb', line 48

def <<(data)
  @obj.string << data
  self
end


40
41
42
# File 'lib/io-string-proxy.rb', line 40

def print(*objs)
  @obj.puts(*objs)
end

#puts(*lines) ⇒ Object



34
35
36
37
38
# File 'lib/io-string-proxy.rb', line 34

def puts(*lines)
  lines.map! {|line| line.end_with?("\n") ? line : line+"\n" }
  # @stdout.puts "STDOUT: #{lines.inspect}"
  lines.each { |l| self << l}
end

#readline(prompt = "") ⇒ Object



22
23
24
25
26
27
28
# File 'lib/io-string-proxy.rb', line 22

def readline(prompt="")
  begin
    @obj.readline()
  rescue EOFError
    ""
  end
end

#readlinesObject



57
58
59
60
61
62
# File 'lib/io-string-proxy.rb', line 57

def readlines
  pos = @obj.pos
  string = @obj.string[pos..-1]
  @obj.pos = @obj.size
  return string
end

#stringObject



30
31
32
# File 'lib/io-string-proxy.rb', line 30

def string()
  @obj.string
end

#tty?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/io-string-proxy.rb', line 53

def tty?
  false
end

#write(data) ⇒ Object



44
45
46
# File 'lib/io-string-proxy.rb', line 44

def write(data)
  @obj.write data
end