Created
December 12, 2016 22:39
-
-
Save stujo/3acc29eb27358ca749788aca8b7fd3e6 to your computer and use it in GitHub Desktop.
Using Mix-Ins with the Abstract Method Pattern
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
# The SuperPower blast_them method depends on the abstract method projectile | |
module Blastable | |
def blast_them | |
puts "BLASTING: #{projectile} (#{self.class.name})" | |
end | |
end | |
class Tyrannosaurus | |
include Blastable | |
def projectile | |
'Laser Beams' | |
end | |
end | |
class Hedgehog | |
include Blastable | |
def projectile | |
'Sonic Boom' | |
end | |
end | |
Tyrannosaurus.new.blast_them | |
Hedgehog.new.blast_them |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment