Class: RubiksCli::Loop::Engine
- Inherits:
-
Object
- Object
- RubiksCli::Loop::Engine
- Defined in:
- lib/rubiks_cli/loop/engine.rb
Instance Method Summary collapse
-
#initialize(on_enter, other_actions) ⇒ Engine
constructor
A new instance of Engine.
- #start ⇒ Object
Constructor Details
#initialize(on_enter, other_actions) ⇒ Engine
Returns a new instance of Engine.
8 9 10 11 12 13 14 15 16 |
# File 'lib/rubiks_cli/loop/engine.rb', line 8 def initialize(on_enter, other_actions) commands = other_actions.map { |action| action.command } if commands.uniq.size != commands.size raise ArgumentError, "Duplicate command" end @actions = Hash.new(on_enter) other_actions.each { |action| @actions[action.command] = action.function } end |
Instance Method Details
#start ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/rubiks_cli/loop/engine.rb', line 18 def start @actions['h'].call loop do input = gets.chomp.downcase Clear.line_above @actions[input].call end end |