Dong! Dong! Dong!

This is a simple little piece of code that simulates a grandfather clock, it checks the current time and returns the hour by printing the word “Dong” once for each hour. It was an exercise in Chris Pine’s “Learn to Program” book.

I wanted to share some Ruby with you guys 🙂 Enjoy!

def dongAway
number = Time.now.hour
if number > (12)
number = number – (12)
end

number.times do
puts “Dong!”
end
end

dongAway

Advertisements