Skip to content

Instantly share code, notes, and snippets.

@sergiolopes
Created January 5, 2010 11:01
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 sergiolopes/269317 to your computer and use it in GitHub Desktop.
Save sergiolopes/269317 to your computer and use it in GitHub Desktop.
exemplo de polimorfismo e duck typing
class Pato
def quack
puts 'quack'
end
end
class PatoEstranho
def quack
puts 'quaaaack'
end
end
# uso normal
p = Pato.new
p.quack
p2 = PatoEstranho.new
p2.quack
# usando o polimorfismo
def fazQuack(pato)
pato.quack
end
fazQuack(Pato.new)
fazQuack(PatoEstranho.new)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment