irb: the interactive shell

Contents
Start irb
Try expressions
Help and tab completion
Exit

Start irb

irb is the interactive Ruby shell: a prompt that runs each line the moment you press Enter. Open it with one command and you will see a prompt waiting for input.

Read more about interactive mode on the Ruby hub page, then come back and type along.

Open the interactive shell

irb

irb(main):001>

Try expressions

Inside irb every line is a small program. Type an expression, press Enter, and irb prints the result right away. The comment after each line below shows what irb prints back.

2 + 2 # => 4 "hi" * 3 # => "hihihi" name = "Ada" # => "Ada" puts "Hello, #{name}" # prints Hello, Ada

Nothing is saved to a file here, so irb is perfect for quick checks. When an idea works in irb, copy it into a script file later.

Help and tab completion

irb completes code for you. Type the first letters of a word such as puts and press Tab twice: irb shows or finishes the matching names.

The launcher also documents itself. Run it with the help flag to list the available options:

List irb command line options

irb --help

Exit

When you are done experimenting, leave the shell and return to the normal terminal. Either type the exit command or press Ctrl+D on an empty line.

Leave the interactive shell

exit

Next: Your first Ruby script

Article author: Arthur Isaev

Related articles
Ruby
Ruby course: zero to hero in 50 lessons
What is Ruby and where it runs
Install Ruby and check the version
irb: the interactive shell
Your first Ruby script
Variables
Numbers
Strings
Symbols
Truthiness: only false and nil
Conditions
Loops
Arrays
Hashes
Ranges
Methods
Blocks, procs, lambdas
String tools
Files and IO
Exceptions
Modules and mixins
Classes and objects
Inheritance
Enumerables
Duck typing and core idioms
Gems and Bundler
Testing with Minitest
Debugging
Encodings
Time and date
JSON and YAML
HTTP clients
Sockets
REST APIs
puts, print and p
Metaprogramming
Enumerators
Pattern matching
Arguments: splats and kwargs
Rake tasks
Environment and CLI
Logging
CSV
ERB templates
WEBrick server
Rails in one lesson
Capstone: todo CLI
Capstone: JSON API
Performance
Modern Ruby tour
Hero roadmap: the whole course on one page
Install Ruby on Windows 11
Install Ruby on Ubuntu
Install Ruby on Rocky Linux
Install Ruby on macOS
Install Ruby on FreeBSD
Ruby in Docker
Threads and fibers
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: