Class: IRB::FileInputMethod

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

Overview

Use a File for IO with irb, see InputMethod

Instance Attribute Summary collapse

Attributes inherited from InputMethod

#prompt

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from InputMethod

#readable_after_eof?, #winsize

Constructor Details

#initialize(file) ⇒ FileInputMethod

Creates a new input method object



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

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

Instance Attribute Details

#file_nameObject (readonly)

The file name of this input method, usually given during initialization.



144
145
146
# File 'lib/irb/input-method.rb', line 144

def file_name
  @file_name
end

Class Method Details

.open(file, &block) ⇒ Object



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

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

Instance Method Details

#closeObject



172
173
174
# File 'lib/irb/input-method.rb', line 172

def close
  @io.close
end

#encodingObject

The external encoding for standard input.



163
164
165
# File 'lib/irb/input-method.rb', line 163

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)


150
151
152
# File 'lib/irb/input-method.rb', line 150

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

#getsObject

Reads the next line from this input method.

See IO#gets for more information.



157
158
159
160
# File 'lib/irb/input-method.rb', line 157

def gets
  print @prompt
  @io.gets
end

#inspectObject

For debug message



168
169
170
# File 'lib/irb/input-method.rb', line 168

def inspect
  'FileInputMethod'
end