Skip to content

Instantly share code, notes, and snippets.

@pirj
Created August 4, 2013 22:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pirj/6152272 to your computer and use it in GitHub Desktop.
Save pirj/6152272 to your computer and use it in GitHub Desktop.
Template module
class BaseWall
def self.Wall length, width, material
Module.new do
define_method(:length) { length }
define_method(:width) { width }
define_method(:material) { material }
def self.included clazz
private :length, :width, :material
end
end
end
def dimensions
"I am #{length}ft. long and #{width}ft. wide!"
end
def made_from
"I am made from #{material}!"
end
end
class BrickWall < BaseWall
include Wall(30, 20, 'brick')
end
class ConcreteWall < BaseWall
include Wall(30, 20, 'concrete')
end
class WoodWall < BaseWall
include Wall(10, 20, 'wood')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment