Last active
August 29, 2015 13:56
-
-
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?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# = 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