This file contains hidden or 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
defimpl Shape, for: Square do | |
def area(shape) do | |
shape.side * shape.side | |
end | |
end |
This file contains hidden or 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
defimpl Shape, for: Circle do | |
def area(shape) do | |
shape.radius * shape.radius * 3.14 | |
end | |
end |
This file contains hidden or 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
%Square{side: 10} | |
|> Shape.area() #=> 100 |
This file contains hidden or 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
defmodule EquilateralTriangle do | |
defstruct [:side] | |
end |
This file contains hidden or 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
defimpl Shape, for: EquilateralTriangle do | |
def area(shape) do | |
# some basic high school math that I've forgotten | |
end | |
end |
This file contains hidden or 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
defmodule Project do | |
def total_cost(shape, cost_per_square_meter) do | |
Shape.area(shape) * cost_per_square_meter | |
end | |
end |
This file contains hidden or 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
defmodule Square do | |
defstruct [:side] | |
end | |
defmodule Circle do | |
defstruct [:radius] | |
end | |
defmodule EquilateralTriangle do | |
defstruct [:side] |
This file contains hidden or 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 Square | |
def initialize(side) | |
@side = side | |
end | |
def area() | |
@side * @side | |
end | |
end |
This file contains hidden or 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 | |
def initialize(radius) | |
@radius = radius | |
end | |
def area() | |
3.14 * @radius * @radius | |
end | |
end |
This file contains hidden or 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
defmodule Square do | |
defstruct [:side] | |
end | |
defmodule Circle do | |
defstruct [:radius] | |
end | |
defmodule Area do | |
def calculate(shape) do |