Welcome to the sixth installment of the Hello World in Every Language series. Today, we’re going to implement Hello World in Ruby.
If you didn’t know, up to this point I’ve been more or less familiar with all the languages I’ve written about. Now, I’m trying my hand at a language I’ve never used, Ruby. Because of that, I hope you’ll reserve your harsh judgments as I trudge through this tutorial.
Table of Contents
As a Ruby novice, I had to consult Wikipedia like usual to learn more about the language.
According to Wikipedia, Ruby is a general-purpose language that first appeared back in 1995 in Japan. Apparently, Ruby is a truly object-oriented language in the sense that almost everything is an object. In fact, even numbers are objects in Ruby which means they can be subjected to the dot operator. How cool is that?
Today, the other major industry languages like Python and Java are more popular general-purpose languages, so Ruby often finds its place as a web development language. This is probably due to the Ruby on Rails framework which helps developers build web applications quickly and easily.
Hello World in Ruby
If we look back at our implementation of Hello World in Python, we’ll remember that the implementation only requires one line of code. Well, somehow Hello World in Ruby requires even less code:
puts "Hello, World!"
That’s it. The puts method is available out of the box. Since almost everything in Ruby is an object, we can probably assume that this method comes from the core Object. In fact, I dug a bit deeper to find that puts comes from Kernel which is a class baked into the Object class, the default superclass. We can actually prove this by calling the following:
This code snippet returns Kernel which is the class that puts comes from. And, that’s it! Hello World in Ruby in just a single line of code.
How to Run the Solution
If we want to run either of these snippets, here’s an online Ruby interpreter.
Alternatively, we can download and install the latest Ruby interpreter. After that, we’ll want to get a copy of the solution. Assuming Ruby is in our environment, all we have to do is run the following:
And, that should run the script!
Sample Programs in Every Language
With Ruby out of the way, I think I’ll jump back on the “proprietary” train and visit Objective-C and Swift in the next couple tutorials. I’m excited to learn about the inspiration for both of those languages.