Skip to content

Instantly share code, notes, and snippets.

@stevecass
Created November 25, 2014 16:35
Show Gist options
  • Save stevecass/3672e794ffcaa7f74bec to your computer and use it in GitHub Desktop.
Save stevecass/3672e794ffcaa7f74bec to your computer and use it in GitHub Desktop.
Duck typing
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}" }
@stevecass
Copy link
Author

Output

#<Person:0x007fb8f3162110> says Bad impression of Donald Duck
#<Duck:0x007fb8f31620e8> says Quack quack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment