irb

irb (Interactive Ruby) was developed by Keiju Ishitsuka. It allows you to enter commands at the prompt and have the interpreter respond as if you were executing a program. irb is useful to experiment with or to explore Ruby.

irb [ options ] [ programfile ] [ argument... ]

Here are the irb options:

-f

Suppresses loading of ~/.irbrc.

-m

Math mode. Performs calculations using rational numbers.

-d

Debugger mode. Sets $DEBUG to true.

-r lib

Uses require to load the library lib before executing the program.

-v
--version

Displays the version of irb.

--inspect

Inspect mode (default).

--noinspect

Noninspect mode (default for math mode).

--readline

Uses the readline library.

--noreadline

Suppresses use of the readline library.

--prompt mode
--prompt-mode mode

Sets the prompt mode. Predefined prompt modes are default, simple, xmp, and inf-ruby.

--inf-ruby-mode

Sets the prompt mode to inf-ruby and suppresses use of the readline library.

--simple-prompt

Sets the prompt mode to simple mode.

--noprompt

Suppresses the prompt display.

--tracer

Displays a trace of method calls.

--back-trace-limit n

Sets the depth of backtrace information to be displayed (default is 16).

Here is a sample irb interaction:

irb irb(main):001:0> a = 25 25 irb(main):002:0> a = 2 2 irb(main):003:0> matz@ev[sample] irb irb(main):001:0> a = 3 3 irb(main):002:0> a.times do |i| irb(main):003:1* puts i irb(main):004:1> end 0 1 2 3 irb(main):005:0> class Foo<Object irb(main):006:1> def foo irb(main):007:2> puts "foo" irb(main):008:2> end irb(main):009:1> ...

Get Ruby in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.