1. Computing
Michael Morin

The Holiday Spirit in Ruby (a "Hello World" Variant)

By December 22, 2008

Follow me on:

There's no better time to start engaging your little ones in the art of programming with Ruby. (Of course, the same could be said for your older, non-Rubyist loved ones.) The holidays offers the perfect opportunity to show how simple it can actually be to not only spread some joy, but to write a program to do so.

To do this, consider the simplicity of the puts method. Using just the puts method, a beginning Rubyist can write a holiday version of the prototypical "Hello World" program. While the below code example prints the words to "We Wish You a Merry Christmas" it can be easily modified to spread the joy of whatever holiday you celebrate!

puts "We wish you a Merry Christmas"
puts # Extra newline
puts "We", "wish", "you", "a" , "Merry Christmas"
puts "We", "wish", "you", "a" , "Merry Christmas"
puts "and a", [ "Happy", "New", "Year!" ]

If you prefer not to create this program in your editor of choice, you can download the snippet from us (as an .rb file) and simply run it on the command line. Happy holidays!

No comments yet. Leave a Comment
Leave a Comment

Line and paragraph breaks are automatic. Some HTML allowed: <a href="" title="">, <b>, <i>, <strike>

©2014 About.com. All rights reserved.