Class: Rbsiev::Repl
- Inherits:
-
Object
- Object
- Rbsiev::Repl
- Defined in:
- lib/rbsiev/repl.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(prompt:, verbose: false) ⇒ Repl
constructor
A new instance of Repl.
- #loop ⇒ Object
Constructor Details
#initialize(prompt:, verbose: false) ⇒ Repl
13 14 15 16 17 |
# File 'lib/rbsiev/repl.rb', line 13 def initialize(prompt:, verbose: false) @verbose = verbose @prompt = prompt @components = init_components end |
Class Method Details
.start(prompt: "REPL> ", verbose: false) ⇒ Object
8 9 10 11 |
# File 'lib/rbsiev/repl.rb', line 8 def self.start(prompt: "REPL> ", verbose: false) msg = Repl.new(prompt: prompt, verbose: verbose).loop puts msg if msg end |
Instance Method Details
#loop ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rbsiev/repl.rb', line 19 def loop second_prompt = "." * (@prompt.length - 1) + " " msg = Kernel.loop { begin source = read_source(second_prompt) rescue EOFError => _ break "Bye!" else next if source.nil? end begin @components.exec(source) rescue Error => e puts e. next end } msg end |