![Forrest logo](/images/logo.png)
ruby:tldr:42e18
IRB stands for Interactive Ruby, and it is a command-line tool that allows you to interactively execute Ruby code. It provides a Read-Eval-Print Loop (REPL) environment where you can write Ruby code and see the results immediately.
When you run the command "irb" in your terminal or command prompt, it starts an IRB session. It opens a prompt where you can type Ruby code and press Enter to execute it. The code is then evaluated, and the result is printed on the next line.
Here's an example:
$ irb
irb(main):001:0> puts "Hello, World!"
Hello, World!
=> nil
irb(main):002:0> x = 5 + 3
=> 8
irb(main):003:0> x * 2
=> 16
irb(main):004:0> exit
In the example above, the IRB session starts, and we print "Hello, World!". The output is displayed immediately after the execution. Then we define a variable x
and assign it the value of 5 + 3
. When we multiply x
by 2, the result is displayed again. Finally, we exit the IRB session by typing exit
or pressing Ctrl+C.
IRB is a helpful tool for quickly testing and experimenting with Ruby code without the need to write a complete program or file. It allows you to play around with Ruby code interactively, gaining a deeper understanding of how it works.