• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Testing The Ruby Waters

    September 24, 2014 Aaron Bartell

    As of October 2013 Ruby is supported on IBM i via PowerRuby. This is good news as Ruby has become a very popular programming language for producing web applications because of its simplicity, flexibility, and vast community. In this article we will be introducing you to tools that aid in learning Ruby on IBM i.

    Often times the easiest way to learn a programming language is by starting small and playing with it. Ruby makes this very easy to do with its included Interactive Ruby Shell, or irb for short.

    The irb environment is also called REPL (Read, Evaluate, Print, Loop) because you can enter one or many Ruby statements and have them invoked immediately before your eyes–no compiling nor saving to an IFS file necessary. This makes the iterative testing of code, for learning or debugging purposes, incredibly efficient.

    If you haven’t already, head on over to powerruby.com to download your free copy of PowerRuby so you can follow along.

    Ruby runs in PASE, and for the purposes of this tutorial we will be accessing the IBM i via SSH session and be placed into a bash shell. If these terms are new to you, then please check out my recent Four Hundred Guru article.

    To start an irb session you first need to be in a PASE shell. IBM i ships with the Korn shell, which can be started by typing CALL QP2TERM from a 5250 terminal. The alternative to QP2TERM is using SSH from your laptop to a bash shell on IBM i where you will get timesavers like tab-completion and command history with up/down arrows.

    Below we show logging into IBM i and determining where the irb tool is using the “which” command. If the command isn’t found it will convey a message stating that fact and let you know which folders it looked in.

    Before starting irb it’s always good to check what Ruby version your session is using by running “ruby -v”, as shown below. You can learn more about the changes in each Ruby version from the ruby-lang.org/en/news page.

    If you have multiple versions of Ruby on your machine then you can switch your bash session to a different one by running the following export command. Here we are setting the PATH environment variable to have a new entry at the beginning and then append the existing contents of PATH (i.e. $PATH). Think of PATH as being similar to a library list–it is what PASE programs will look at to resolve dependencies. Note that as of this writing only Ruby version 2.0 is supported since version 1.9 is being end-of-life’d in February of 2015.

    export PATH=/PowerRuby/prV1R9/bin:$PATH
    

    Now we are ready to start the interactive Ruby shell by typing “irb” in bash, as shown below. As you can see we are presented with a new prompt and this is where we can start typing any Ruby syntax.

    As I mentioned in the introduction, irb is a great way to learn Ruby because it makes it very quick and easy to test different statements, so let’s put that thought to the test. One feature of Ruby is parentheses on method calls, which are optional. To learn whether this is true we can call the puts method, first without parentheses and then with them.

    We can now see it worked both ways and have a better understanding of calling Ruby methods with and without parentheses. You might be wondering what the displayed “=> nil” value means. In short, every method in Ruby returns a value and if you don’t specify one then nil is returned. In the case of “puts” it only sends the input parameter to standard output and doesn’t return anything else, so nil is returned and displayed.

    Another aspect of Ruby we can test is whether everything is an object, or more specifically that Ruby doesn’t have native data types as other languages do. Using the “.class” method we can determine what class an object comes from. In the below screenshot we learn the number 20 is actually a Fixnum class and the “false” Ruby-reserved-word is based on FalseClass. In other languages like Java and RPG both of these would be native data types that have no underlying objects.

    A next question might be “what difference does it make if a number is an object?” To answer that question it would be good to learn what capabilities Fixnum has by typing “20.methods”, as shown below.

    Wow! That’s a lot of functionality. One that looks intriguing is the “between?” method, so let’s try and invoke it. Note that question marks are valid characters to have in method names and declare to the programmer a boolean is the expected return value.

    As we can see, when no arguments are passed it errors and tells us how many it is expecting (or we can look at the documentation). Let’s call it again with two numbers. Remember, parentheses on method calls are optional. By doing this test we also learn the “between?” method is inclusive of the number itself. In this case we are using a literal number but a more likely situation would be a variable holding a number.

    Once you are done using irb you can exit by typing “quit” and you will be returned to the bash shell, as shown below.

    If you aren’t allowed to load PowerRuby on your machine then you can head over to tryruby.org to walk through tutorials using an irb-like tool completely from the browser. If you are a little more adventurous you can download a Ruby runtime onto your laptop. Ruby runs on most any platform. Also, if you are already versed in another language like C/C++, Java, Perl, PHP, or Python, then check out this comparison page to see what’s different.

    I hope this tutorial has been informative and shows how simple it is to test the waters with Ruby on IBM i. I will leave you with something additional to test: determine whether string interpolation in Ruby works for both single- and double-quoted strings. Remember, Google is your friend.

    Aaron Bartell is a Rubyist at heart, though it wasn’t always that way. Going back more than a decade has Aaron loving RPG and Java as they were the primary means of creating mobile or website solutions on IBM i. That all changed when he was introduced to the Ruby language and Rails web framework because it became very apparent how much time and effort could be saved to produce excellent applications. Ruby on i is now a reality with PowerRuby, so what are you waiting for!? Aaron lives with his wife and five children in southern Minnesota. He enjoys the vast amounts of laughter having a young family brings, along with camping and music. Send your questions or comments for Aaron to Ted Holt via the IT Jungle Contact page.

    RELATED STORY

    Bash Is Not A Shell Game



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    New Generation Software

    FREE Webinar:

    Creating Great Data for Enterprise AI

    Enterprise AI relies on many data sources and types, but every AI project needs a data quality, governance, and security plan.

    Wherever and however you want to analyze your data, adopting modern ETL and BI software like NGS-IQ is a great way to support your effort.

    Webinar: June 26, 2025

    RSVP today.

    www.ngsi.com – 800-824-1220

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Profound Logic Software:  October 1 Webinar: "See What i Can Do with Mobile Applications"
    System i Developer:  Upgrade your skills at the RPG & DB2 Summit in Minneapolis, Sept 30 - Oct 2.
    LANSA:  Getting ready to build a mobile app? Webinar: September 24, 12 pm CT/1 pm ET

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    Oracle Teams with Secure-24 for JD Edwards Hosting Cisco’s UCS Mini Enters The Midrange Arena

    Leave a Reply Cancel reply

Volume 14, Number 22 -- September 24, 2014
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
Bug Busters Software Engineering

Table of Contents

  • Testing The Ruby Waters
  • A Bevy Of BIFs: %ScanRpl (Scan And Replace)
  • Admin Alert: What’s The Danger Zone For IBM i Disk Utilization?

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle