Last active
January 27, 2017 10:47
-
-
Save andreapavoni/15baeefe71f34255c4a4cd8ea9ec9bdd to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
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