Skip to content

Instantly share code, notes, and snippets.

@bryanmikaelian
Created June 20, 2011 15:55
Show Gist options
  • Save bryanmikaelian/1035868 to your computer and use it in GitHub Desktop.
Save bryanmikaelian/1035868 to your computer and use it in GitHub Desktop.
Simple Polymorphism - Now with more cheese
class Cheese
attr_reader :name
def initialize
@name = "cheese"
end
def eat_cheese(cheese)
puts "This " + cheese.name + " is great!"
end
end
class CheddarCheese < Cheese
attr_reader :name
def initialize
@name = "cheddar cheese"
end
end
cc = CheddarCheese.new
cc.eat_cheese(cc) # puts 'This cheddar cheese is great.'
@jessedearing
Copy link

Not only is this polymorphism, but it uses the Decorator Pattern (http://en.wikipedia.org/wiki/Decorator_pattern)

@bryanmikaelian
Copy link
Author

Great to know! Thanks!

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