Last active
August 29, 2015 14:04
-
-
Save Lorrainehope98/b2e280ed43b60e3ec304 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
kaiwren/rbmonk-class-example.rb | |
class Rectangle | |
def initialize(length, breadth) | |
@length = length | |
@breadth = breadth | |
end | |
def perimeter | |
2 * (@length + @breadth) | |
end | |
def area | |
@length * @breadth | |
end | |
end | |
rectangle = Rectangle.new(5, 2) | |
puts rectangle.perimeter | |
puts rectangle.area |
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
#Area = ½ × b × h | |
#b = base | |
#h = vertical height | |
class Triangle | |
def initialize(base, height) | |
@base = base | |
@height = height | |
end | |
def area | |
@base * @height /2 | |
end | |
end | |
triangle = Triangle.new(20, 10) | |
puts triangle.area |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Going to try a circle next #Circle
Area = π × r2
Circumference = 2 × π × r
r = radius