iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💎
How to run IRB (Interactive Ruby)
What is irb?
irb stands for interactive ruby.
It is a tool for easily entering and executing Ruby expressions from standard input.
- by Official
What you can do with irb
By using the irb command from the terminal, you can execute Ruby code line by line on your terminal.
It is a very powerful tool when you want to try out Ruby quickly.
Since you don't need to create a file every time, it is extremely convenient for running small Ruby commands.
Installing irb
You can easily install it using gem.
$ gem install irb
Fetching irb-1.2.7.gem
Fetching io-console-0.5.6.gem
Fetching reline-0.1.8.gem
Building native extensions. This could take a while...
Successfully installed io-console-0.5.6
Successfully installed reline-0.1.8
Successfully installed irb-1.2.7
Parsing documentation for io-console-0.5.6
Installing ri documentation for io-console-0.5.6
Parsing documentation for reline-0.1.8
Installing ri documentation for reline-0.1.8
Parsing documentation for irb-1.2.7
Installing ri documentation for irb-1.2.7
Done installing documentation for io-console, reline, irb after 2 seconds
3 gems installed
Trying out irb
After installation, just type irb.
$ irb
irb(main):001:0>
For example, let's use the puts command to display "Hello, world".
irb(main):001:0> puts "Hello, world!"
Hello, world!
=> nil
irb(main):002:0>
It's simple. It is much easier to try out than creating a Ruby file and running it with the ruby command.
Exiting irb
Type exit and press Enter to return to the regular terminal.
irb(main):001:0> exit
$
Discussion