Class: IRBRemote::InputMethod

Inherits:
IRB::InputMethod
  • Object
show all
Defined in:
lib/irb_remote/input_method.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, output) ⇒ InputMethod

Creates a new input method object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/irb_remote/input_method.rb', line 4

def initialize(input, output)
  super()

  @line_no = 0
  @line = []
  @eof = false

  input.set_encoding(IRB.conf[:LC_MESSAGES].encoding, '-')
  output.set_encoding(IRB.conf[:LC_MESSAGES].encoding, '-')

  @stdin = input
  @stdout = output
end

Instance Method Details

#encodingObject

The external encoding for standard input.



53
54
55
# File 'lib/irb_remote/input_method.rb', line 53

def encoding
  @stdin.external_encoding
end

#eof?Boolean

Whether the end of this input method has been reached, returns true if there is no more data to read.

See IO#eof? for more information.

Returns:

  • (Boolean)


31
32
33
# File 'lib/irb_remote/input_method.rb', line 31

def eof?
  @stdin.eof?
end

#getsObject

Reads the next line from this input method.

See IO#gets for more information.



21
22
23
24
25
# File 'lib/irb_remote/input_method.rb', line 21

def gets
  @stdout.print @prompt
  line = @stdin.gets
  @line[@line_no += 1] = line
end

#line(line_no) ⇒ Object

Returns the current line number for #io.

#line counts the number of times #gets is called.

See IO#lineno for more information.



48
49
50
# File 'lib/irb_remote/input_method.rb', line 48

def line(line_no)
  @line[line_no]
end

#readable_after_eof?Boolean

Whether this input method is still readable when there is no more data to read.

See IO#eof for more information.

Returns:

  • (Boolean)


39
40
41
# File 'lib/irb_remote/input_method.rb', line 39

def readable_after_eof?
  true
end