Class: IRB::FileInputMethod

Inherits:
InputMethod show all
Defined in:
lib/irb/input-method.rb

Overview

Use a File for IO with irb, see InputMethod

Constant Summary

Constants inherited from InputMethod

InputMethod::BASIC_WORD_BREAK_CHARACTERS

Instance Attribute Summary

Attributes inherited from InputMethod

#prompt

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from InputMethod

#prompting?, #readable_after_eof?, #support_history_saving?, #winsize

Constructor Details

#initialize(file) ⇒ FileInputMethod

Creates a new input method object

[View source]

139
140
141
142
# File 'lib/irb/input-method.rb', line 139

def initialize(file)
  @io = file.is_a?(IO) ? file : File.open(file)
  @external_encoding = @io.external_encoding
end

Class Method Details

.open(file, &block) ⇒ Object

[View source]

128
129
130
131
132
133
134
135
# File 'lib/irb/input-method.rb', line 128

def open(file, &block)
  begin
    io = new(file)
    block.call(io)
  ensure
    io&.close
  end
end

Instance Method Details

#closeObject

[View source]

170
171
172
# File 'lib/irb/input-method.rb', line 170

def close
  @io.close
end

#encodingObject

The external encoding for standard input.

[View source]

161
162
163
# File 'lib/irb/input-method.rb', line 161

def encoding
  @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)
[View source]

148
149
150
# File 'lib/irb/input-method.rb', line 148

def eof?
  @io.closed? || @io.eof?
end

#getsObject

Reads the next line from this input method.

See IO#gets for more information.

[View source]

155
156
157
158
# File 'lib/irb/input-method.rb', line 155

def gets
  print @prompt
  @io.gets
end

#inspectObject

For debug message

[View source]

166
167
168
# File 'lib/irb/input-method.rb', line 166

def inspect
  'FileInputMethod'
end