Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Forked from JEG2/inheritance.rb
Created March 8, 2011 19:47
Show Gist options
  • Save practicingruby/860879 to your computer and use it in GitHub Desktop.
Save practicingruby/860879 to your computer and use it in GitHub Desktop.
module Measurable
def area
width * height
end
attr_reader :width, :height
end
class Rectangle
include Measurable
def initialize(width, height)
@width = width
@height = height
end
end
class Square
include Measurable
def initialize(side_length)
@width = side_length
@height = side_length
end
end
p Square.new(4).area
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment