Skip to content

Instantly share code, notes, and snippets.

@stujo
Created December 12, 2016 22:39
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 stujo/3acc29eb27358ca749788aca8b7fd3e6 to your computer and use it in GitHub Desktop.
Save stujo/3acc29eb27358ca749788aca8b7fd3e6 to your computer and use it in GitHub Desktop.
Using Mix-Ins with the Abstract Method Pattern
# 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