Skip to content

Instantly share code, notes, and snippets.

@jakeboxer
Created March 12, 2014 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakeboxer/9517314 to your computer and use it in GitHub Desktop.
Save jakeboxer/9517314 to your computer and use it in GitHub Desktop.
#######
# Bad #
#######
class Dog
end
class Cat
end
class Human
end
def speak(animal)
if animal.is_a?(Dog)
puts "woof"
elsif animal.is_a?(Cat)
puts "meow"
elsif animal.is_a?(Human)
puts "twerk"
end
end
########################################################################
########
# Good #
########
class Dog
def noise
"woof"
end
end
class Cat
def noise
"meow"
end
end
class Human
def noise
"twerk"
end
end
def speak(animal)
puts animal.noise
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment