Skip to content

Instantly share code, notes, and snippets.

@danreedy
Created December 24, 2014 10:49
Show Gist options
  • Save danreedy/6f4c2fdcabc027d35757 to your computer and use it in GitHub Desktop.
Save danreedy/6f4c2fdcabc027d35757 to your computer and use it in GitHub Desktop.
jingle_bells.rb
#!/usr/bin/env ruby
class JingleBells
def initialize
@jingle_count = 0
end
def can_jingle?
@jingle_count < 2
end
def jingle
@jingle_count += 1
'Jingle Bells'
end
def all_the_way
'Jingle All the Way'
end
end
class Sleigh
attr_reader :number_of_horses, :type
def initialize(number_of_horses: 2, type: :coach)
@number_of_horses = number_of_horses
@type = type
end
def fun_to_ride?
@number_of_horses == 1 && @type == :open
end
end
jingle_bells = JingleBells.new
3.times do
if jingle_bells.can_jingle?
puts jingle_bells.jingle
else
puts jingle_bells.all_the_way
end
end
sleigh = Sleigh.new(number_of_horses: 1, type: :open)
if sleigh.fun_to_ride?
puts "Oh what fun it is to ride a #{sleigh.number_of_horses} horse #{sleigh.type} sleigh"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment