Skip to content

Instantly share code, notes, and snippets.

@Lorrainehope98
Last active August 29, 2015 14:04
Show Gist options
  • Save Lorrainehope98/b2e280ed43b60e3ec304 to your computer and use it in GitHub Desktop.
Save Lorrainehope98/b2e280ed43b60e3ec304 to your computer and use it in GitHub Desktop.
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
#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
@Lorrainehope98
Copy link
Author

Going to try a circle next #Circle

Area = π × r2

Circumference = 2 × π × r

r = radius

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment