What is a benefit of using Interactive Ruby (IRb)? (intro Ruby tips)


I would say one good scenario where Ruby’s interactive environment (IRb) could be very helpful and useful over coding or scripting in text editors is; testing code or scripts in real time, for a purpose such as unit testing.

What is (IRb)?

“Interactive Ruby (IRb) provides a shell for experimentation. Within the IRb shell, you can immediately view expression results, line by line. This tool comes along with Ruby installation so you have nothing to do extra to have IRb working. Just type irb at your command prompt and an Interactive Ruby Session will start as given below –

$irb
irb 0.6.1(99/09/16)
irb(main):001:0> def hello
irb(main):002:1> out = "Hello World"
irb(main):003:1> puts out
irb(main):004:1> end
nil
irb(main):005:0> hello
Hello World
nil
irb(main):006:0>

As explained and demoed on the concise article on the topic titled ‘Ruby – Environment Setup’  found at; https://www.tutorialspoint.com/ruby/ruby_environment.htm

So, how does it (IRb) work?

The program is launched from a command line and allows the execution of Ruby commands with immediate response, experimenting in real-time. It features command history, line editing capabilities, and job control, and is able to communicate directly as a shell script over the Internet and interact with a live server. It was developed by Keiju Ishitsuka.”  describes Wikipedia in it’s article; https://en.wikipedia.org/wiki/Interactive_Ruby_Shell

Useful articles:

  • https://www.tutorialspoint.com/ruby/ruby_environment.htm
  • http://ruby-doc.com/docs/ProgrammingRuby/html/irb.html

Published by

admin

I’m Cameron Cashwell, I’ve been a Web Developer for 6+ years. I’m always on the look out for exciting new projects and ideas. Wanna work together? http://www.cdev.co/#request

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz