Class: Mayl::Repl
- Inherits:
-
Object
- Object
- Mayl::Repl
- Defined in:
- lib/mayl/repl.rb
Overview
Public: The class responsible for reading user input, interpreting it and executing associated commands.
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize(path) ⇒ Repl
constructor
Public: Initializes a new REPL from a given path.
-
#start ⇒ Object
Public: Fires up the REPL that parses and executes given commands.
Constructor Details
Instance Attribute Details
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
5 6 7 |
# File 'lib/mayl/repl.rb', line 5 def parser @parser end |
Instance Method Details
#start ⇒ Object
Public: Fires up the REPL that parses and executes given commands.
Returns nothing.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mayl/repl.rb', line 19 def start locales = @env.locales.map(&:name) prompt = "> " puts "Detected locales: #{locales.join(', ')}" while (print prompt; input = gets) begin value = @parser.parse(input.chomp).execute @env.last_value = value @env.commit prompt = [@env.namespace, '> '].reject(&:empty?).join ' ' rescue => e print "Error: #{e.}" ensure print "\n" end end end |