Tuesday, August 11, 2009

Interactive Ruby

One way to run Ruby interactive is simply to type ruby at the shell prompt. Here we typed in the single puts expressions and an end-of-file character (which is Ctrl+D on our system). This process works, but it's painful if you make typo, and you can't really see what's going on as you type.

%ruby
puts "Hello, world!"

For most folks, irb--Interactive Ruby--is the tool of choice for executing Ruby interactive.irb is a Ruby Shell, complete with command-line history,line-editing capabilities, and job control.You run irb from the command line. Once it starts, just type in Ruby code. It will show you the value of each expression as it evaluates it.

%irb

We recommend that you get familiar with the irb so you can try some of our examples interactively.

There's a trick when you want to use irb to try example code that's already in a file. You can do this from within irb loading in the program file and then calling methods it contains. In this case, the program file is in code/rdoc/fib_example.rb.

%irb

No comments:

Post a Comment