Ruby Day 1

My experience with day one of exploring Ruby through Seven Languages in Seven Weeks.

Unlike most of the other languages in the book Ruby isn’t completely new to me. I’ve been playing with it on and off for a number of years and recently used it for an online SaaS course. I guess that makes it a good first language to look at. Something to ease me in gently.

One of the parts of the book I’ve really enjoyed so far is the interview with the language author, in Ruby’s case Yukihiro Matsumoto. It’s interesting to see what inspired the author to write the language and how it went from a hobbie to something used in commercial applications today. I like the fact he decided to focus on programmer efficiency rather than going for pure execution speed. You can definitely see it in the syntax. It feels pleasant to read and write.

Ruby is an open source language with a strong support community so if I get stuck at any point I know it won’t be difficult to find some support online.

It is an Object Orientated language but unlike Java it is a pure Object Orientated Language where almost everything is an object. None of this mucking about with primitive types even numbers like 4 are objects with their own set of methods.


One of the first examples of the programmer friendly syntax is the ability to express simple conditions in a single line

instead of

Another user friendly syntax is the idea of unless. Much more intuitive than not


In Ruby you can only inherit from a single parent class. However it supports a concept called ‘Duck Typing’. If it walks like a duck and quacks like a duck, it’s a duck i.e. our classes don’t have to inherit from the same parent to be used in the same way. Ruby is more concerned with what methods can be called on an object and what operations can be performed on it.

String and float both have a to_i method and so can both act as ‘a’ in the following piece of code.

Ruby is a free-spirited language that will let you do just about anything, including changing core classes like NilClass and String. This gives you a lot of freedom and power but shouldn’t be used lightly. You need to think without the consequences before you make this kind of a change.


Print the string “Hello World”

For the string “Hello, Ruby,” find the index of the word “Ruby”

Print your name 10 times

Print the string “This is sentence number 1” where the number 1 changes from 1 to 10.

Write a program that picks a random number. Let a player guess the number,

Check out my code at github