Created
November 25, 2014 16:35
-
-
Save stevecass/3672e794ffcaa7f74bec to your computer and use it in GitHub Desktop.
Duck typing
This file contains hidden or 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
class Duck | |
def quack | |
"Quack quack" | |
end | |
end | |
class Person | |
def quack | |
"Bad impression of Donald Duck" | |
end | |
end | |
things = [] | |
things << Person.new | |
things << Duck.new | |
things.each { |v| puts "#{v} says #{v.quack}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output