Skip to content

Instantly share code, notes, and snippets.

@andreapavoni
Last active January 27, 2017 10:47
Show Gist options
  • Save andreapavoni/15baeefe71f34255c4a4cd8ea9ec9bdd to your computer and use it in GitHub Desktop.
Save andreapavoni/15baeefe71f34255c4a4cd8ea9ec9bdd to your computer and use it in GitHub Desktop.
module Geometry do
@moduledoc """
Calculates area of different shapes
"""
@doc """
Some other comment
"""
def area({:rectangle, width, height}) do: width * height
def area({:square, side}) do: side * side
def area({:circle, radius}) do: 3.14159 * radius * radius
end
class Circle
attr_accessor :radius
def initialize(radius)
@radius = radius
end
def area
Math::PI * radius**2
end
end
class Square
attr_accessor :side
def initialize(side)
@side = side
end
def area
side**2
end
end
class Rectangle
attr_accessor :width, :height
def initialize(width, height)
@width = width
@height = height
end
def area
width * height
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment