REPL
Learn to execute Ruby programs in the Ruby interactive shell called `irb`, and learn how to run a program from a file.
We'll cover the following...
Hello, I’m your REPL
In the case of the 1 + 1
program from the previous chapter, the interpreter performs two actions: read ® and evaluate (E). We used no “print” action (puts
in our case), so no result was displayed on the screen. In other words, to see the results we need to perform these three actions:
- Read (R)
- Evaluate (E)
- Print (P)
It would also be nice if we could avoid running the ruby
command from the terminal every time, so that we can execute programs in a constant loop (L). It turns out that this functionality is already there! The REPL acronym stands for Read Evaluate Print Loop.
It’s very similar to the Ruby interpreter, but differs in that it accepts the “Enter” key as the end of our program. Instead of exiting on Ctrl+D, signifying end of input, it just starts reading the input ...