Class: Walnut::Input::Readline
- Inherits:
-
Object
- Object
- Walnut::Input::Readline
- Defined in:
- lib/walnut/input/readline.rb
Overview
Readline input plugin
Must implement #read, #gets, and #eof?
Instance Attribute Summary collapse
-
#input_object ⇒ Object
readonly
Returns the value of attribute input_object.
Instance Method Summary collapse
- #close ⇒ Object
-
#eof? ⇒ TrueClass, FalseClass
Check if an EOF has been reached.
-
#gets ⇒ String, NilClass
(also: #read)
Read a line from input.
-
#initialize(parent) ⇒ Readline
constructor
A new instance of Readline.
Constructor Details
#initialize(parent) ⇒ Readline
Returns a new instance of Readline.
17 18 19 20 |
# File 'lib/walnut/input/readline.rb', line 17 def initialize(parent) @walnut = parent @input_object = ::Readline end |
Instance Attribute Details
#input_object ⇒ Object (readonly)
Returns the value of attribute input_object.
15 16 17 |
# File 'lib/walnut/input/readline.rb', line 15 def input_object @input_object end |
Instance Method Details
#close ⇒ Object
41 42 43 |
# File 'lib/walnut/input/readline.rb', line 41 def close @eof = nil end |
#eof? ⇒ TrueClass, FalseClass
Check if an EOF has been reached
35 36 37 |
# File 'lib/walnut/input/readline.rb', line 35 def eof? (@eof.nil?) ? true : false end |
#gets ⇒ String, NilClass Also known as: read
Note:
The instance variable @eof is set to nil when EOF has been reached, see #eof?
Read a line from input
28 29 30 |
# File 'lib/walnut/input/readline.rb', line 28 def gets @eof = @input_object.readline(@walnut[:input].prompt||Walnut[:input].prompt, @walnut[:input].history||[]) end |