Class: Utils::StdinSimulator

Inherits:
Object
  • Object
show all
Defined in:
lib/utils.rb

Overview

Standard input simulator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStdinSimulator

Returns a new instance of StdinSimulator.



6
7
8
9
# File 'lib/utils.rb', line 6

def initialize
  # Represent an input queue as an array
  @input_queue = []
end

Instance Attribute Details

#input_queueObject (readonly)

Returns the value of attribute input_queue.



4
5
6
# File 'lib/utils.rb', line 4

def input_queue
  @input_queue
end

Instance Method Details

#<<(input) ⇒ Object



11
12
13
14
# File 'lib/utils.rb', line 11

def <<(input)
  # Add an element to the input queue
  @input_queue << input
end

#getsObject



16
17
18
19
# File 'lib/utils.rb', line 16

def gets
  # Dequeue the first element in the queue
  @input_queue.shift
end