How to execute Ruby irb (interactive ruby)

What is irb?

irb is an abbreviation for interactive ruby. It is a tool to easily input / execute ruby expressions from standard input. by official

What you can do with irb

You can run ruby line by line on the terminal using the command irb from the terminal. It is a very powerful tool when you want to try ruby easily.

You don't have to create a file every time, which is very convenient when you want to execute a little ruby command.

irb installation

Easy to install with 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

Try irb

After installing, just type irb.

$ irb

For example, use the puts command to display Hello, world.

irb(main):001:0> puts "Hello, world!"
Hello, world!
=> nil

It's easy. It's easier than creating a ruby file and running ruby from the ruby command.

When terminating irb

Type exit and press Enter to return to the normal terminal.

irb(main):001:0> exit

Recommended Posts

How to execute Ruby irb (interactive ruby)
Ruby Learning # 35 Interactive Ruby (irb)
How to use Ruby return
[Ruby] How to comment out
Ruby: How to use cookies
[Ruby] How to write blocks
How to iterate infinitely in Ruby
How to install ruby through rbenv
How to use Ruby on Rails
How to install Bootstrap in Ruby
[Ruby] How to use any? Method
How to use Ruby inject method
How to execute a contract using web3j
How to get date data in Ruby
[Ruby on Rails] How to use CarrierWave
Ruby length, size, count How to use
[Ruby] How to use slice for beginners
[Ruby on Rails] How to use redirect_to
[Easy] How to upgrade Ruby and bundler
[Ruby on Rails] How to use kaminari
Ruby: CSV :: How to use Table Note
How to execute multiple commands in docker-compose.yml
How to deploy
How to find the cause of the Ruby error
[Ruby] How to convert CSV file to Yaml (Yml)
[Ruby on Rails] How to display error messages
How to execute and mock methods using JUnit
How to add / remove Ruby on Rails columns
[Ruby] How to use gsub method and sub method
[Ethereum] How to execute a contract using web3j-Part 2-
How to write code that thinks object-oriented Ruby
How to execute processing before and after
[Ruby] How to generate a random alphabet string
[Ruby on Rails] How to install Bootstrap in Rails
How to execute tasks in parallel in Swift in Swift Package
[Ruby on Rails] How to use session method
[ruby] How to receive values from standard input?
Ruby How to convert between uppercase and lowercase
How to implement Pagination in GraphQL (for ruby)
[Ruby basics] How to use the slice method
How to install Ruby on an EC2 instance on AWS
[Ruby] How to use standard output in conditional branching
How to develop OpenSPIFe
How to call AmazonSQSAsync
How to use Map
How to write Rails
How to use rbenv
How to make LINE messaging function made with Ruby
Rails / Ruby: How to get HTML text for Mail
How to use letter_opener_web
How to use fields_for
How to use java.util.logging
How to use map
How to deal with No template for interactive request
[Ruby] How to find the sum of each digit
[Ruby on Rails] How to change the column name
How to use collection_select
[Ruby] How to use rbenv (version `x.x.x'is not installed)
How to adapt Bootstrap
How to use Twitter4J
How to use active_hash! !!