Last active
March 2, 2016 00:48
-
-
Save SandNerd/aa82fd205faf76abbc20 to your computer and use it in GitHub Desktop.
Meat transformed into a Burger using Ruby's subclassing, include and prepend
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 Meat | |
def burger | |
puts "meat" | |
end | |
end | |
class SauceAndMeat < Meat | |
def burger | |
puts "sauce" | |
super # "meat" | |
end | |
end | |
module Lettuce | |
def burger | |
puts "lettuce" | |
super | |
end | |
end | |
module UpperBun | |
def burger | |
puts "upper_bun" | |
super | |
end | |
end | |
module LowerBun | |
def burger | |
super # notice a difference in ordering? | |
puts "lower_bun" | |
end | |
end | |
SauceAndMeat.include(LowerBun) | |
SauceAndMeat.include(Lettuce) | |
SauceAndMeat.prepend(UpperBun) | |
SauceAndMeat.new.burger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment