Introduction
IRB lets you try Ruby code right away. It helps you learn and test ideas quickly without writing a full program.
IRB lets you try Ruby code right away. It helps you learn and test ideas quickly without writing a full program.
irb
Type irb in your terminal to start the interactive Ruby shell.
Use exit or quit to leave IRB.
irb > 2 + 3 => 5 > puts "Hello" Hello => nil > exit
irb > name = "Alice" > puts "Hello, #{name}!" Hello, Alice! => nil > exit
This example uses IRB to print numbers from 1 to 10 using a loop.
irb > 10.times { |i| puts "Number: #{i + 1}" } Number: 1 Number: 2 Number: 3 Number: 4 Number: 5 Number: 6 Number: 7 Number: 8 Number: 9 Number: 10 => 10 > exit
IRB is great for quick tests but not for full programs.
You can use arrow keys to navigate your command history in IRB.
IRB shows the result of each expression automatically.
IRB is a tool to run Ruby code interactively.
It helps you learn and test code quickly.
Start it by typing irb in your terminal.
irb in Ruby?irb in the terminal.ruby irb, start irb, or run ruby are incorrect for starting IRB.irb to start IRB [OK]5.times { |i| puts i }times methodtimes method runs the block 5 times, with i from 0 to 4.puts i does inside the blocki on a new line, so output is 0,1,2,3,4 each on separate lines.puts 'Hello
def name(params); body; end syntax. def square(x); x * x; end; square(4) follows this correctly.square(4) is correct. The other options have syntax errors or wrong Ruby style.Pass the test and this pattern moves unknown