Skip to content

Instantly share code, notes, and snippets.

@mmcdaris
Last active August 29, 2015 13:56
Show Gist options
  • Save mmcdaris/9282119 to your computer and use it in GitHub Desktop.
Save mmcdaris/9282119 to your computer and use it in GitHub Desktop.
There can be one or many cows! how can you make them all eat their dinner?
# = Cows!
# The Cows are created from this class
#
class Cow
def eats
"munching grass"
end
end
# = Many Cows
#
many_cows = []
3.times { many_cows << Cow.new }
# = One Cow
#
one_cow = Cow.new
# # Dinner Time For the cows!
# But it could be either one, or many
# We don't know if they heard the bell or not!
#
def dinner_time_for(one_or_many_cows)
[one_or_many_cows].flatten.map(&:eat)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment