Hello World in Ruby

Hello World in Ruby Featured Image

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

Ruby Background

As a Ruby novice, I had to consult WikipediaOpens in a new tab. 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 interpreterOpens in a new tab..

Alternatively, we can download and install the latest Ruby interpreterOpens in a new tab.. After that, we’ll want to get a copy of the solutionOpens in a new tab.. Assuming Ruby is in our environment, all we have to do is run the following:

ruby hello-world.rb

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.

I’m not sure where we’re headed after that. There are tons of directions I’d like to take this series, so I may just poke around random languages for awhile. For instance, I’d like to explore some more web development languages like PHP and JavaScript. I’d also like to dig into some assembly languages like x86 and MIPS. We’ll see where this series goes!

Sample Programs in Every Language (44 Articles)—Series Navigation

For 100 Days of Code, I’ve decided to implement a few sample programs in as many languages as possible. Each implementation details a brief history of the language and a description of the code.

The plan for the series is to explore the major general-purpose language like Java, Python, C, C++, and C#. From there, we’ll take a look at some sample programs in web development languages like Ruby, PHP, and JavaScript. As we continue, we’ll cover proprietary languages like Swift and Objective-C. Eventually, we’ll start to tackle less popular languages like Rust, x86, and Verilog. Finally, we’ll play around with some of the esoteric languages like Brainf*ck and LOLCODE.

Who knows? Maybe the Sample Programs in Every Language series will become so popular it’ll never end. To help this series grow, consider sharing it on social media with your friends. Or, if you have a language you want to see, drop your suggestion in the comments.

Jeremy Grifski

Jeremy grew up in a small town where he enjoyed playing soccer and video games, practicing taekwondo, and trading Pokémon cards. Once out of the nest, he pursued a Bachelors in Computer Engineering with a minor in Game Design. After college, he spent about two years writing software for a major engineering company. Then, he earned a master's in Computer Science and Engineering. Today, he pursues a PhD in Engineering Education in order to ultimately land a teaching gig. In his spare time, Jeremy enjoys spending time with his wife, playing Overwatch and Phantasy Star Online 2, practicing trombone, watching Penguins hockey, and traveling the world.

Recent Posts