Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Ruby Programming
Previous Page Home Next Page

Interactive Ruby

If you want to play with Ruby, there is a facility called Interactive Ruby---irb, for short. irb is essentially a Ruby ``shell'' similar in concept to an operating system shell (complete with job control). It provides an environment where you can ``play around'' with the language in real time. You launch irb at the command prompt:

irb [
            irb-options
            ] [
            ruby_script
            ] [
            options
            ]

irb will display the value of each expression as you complete it. For instance:

% irb
irb(main):001:0> 
              a = 1 +
            
irb(main):002:0* 
              2 * 3 /
            
irb(main):003:0* 
              4 % 5
            
2
irb(main):004:0> 
              2+2
            
4
irb(main):005:0> 
              def test
            
irb(main):006:1> 
              puts "Hello, world!"
            
irb(main):007:1> 
              end
            
nil
irb(main):008:0> 
              test
            
Hello, world!
nil
irb(main):009:0> 

irb also allows you to create subsessions, each one of which may have its own context. For example, you can create a subsession with the same (top-level) context as the original session, or create a subsession in the context of a particular class or instance. The sample session shown in Figure 12.1 on page 126 is a bit longer, but shows how you can create subsessions and switch between them.

Figure not available...

For a full description of all the commands that irb supports, see the reference beginning on page 517.

As with the debugger, if your version of Ruby was built with GNU Readline support, you can use arrow keys (as with Emacs) or vi-style key bindings to edit individual lines or to go back and reexecute or edit a previous line---just like a command shell.

irb is a great learning tool: it's very handy if you want to try out an idea quickly and see if it works.
Ruby Programming
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire