Class: Triangle

Inherits:
Object
  • Object
show all
Defined in:
lib/shapelib.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(side_one, side_two, side_three) ⇒ Triangle

Returns a new instance of Triangle.



64
65
66
67
68
69
# File 'lib/shapelib.rb', line 64

def initialize(side_one, side_two, side_three)
  @side_one, @side_two, @side_three = side_one, side_two, side_three
  @perimiter = side_one + side_two + side_three
  @semiperimiter = @perimiter/2.0
  @area = Math.sqrt(((side_one + side_two + side_three) * ((side_one * -1) + side_two + side_three) * (side_one - side_two + side_three) * (side_one + side_two - side_three)) / 16.0)
end

Instance Attribute Details

#areaObject (readonly)

Returns the value of attribute area.



62
63
64
# File 'lib/shapelib.rb', line 62

def area
  @area
end

#perimiterObject (readonly)

Returns the value of attribute perimiter.



62
63
64
# File 'lib/shapelib.rb', line 62

def perimiter
  @perimiter
end

#semiperimiterObject (readonly)

Returns the value of attribute semiperimiter.



62
63
64
# File 'lib/shapelib.rb', line 62

def semiperimiter
  @semiperimiter
end

#side_oneObject

Returns the value of attribute side_one.



62
63
64
# File 'lib/shapelib.rb', line 62

def side_one
  @side_one
end

#side_threeObject

Returns the value of attribute side_three.



62
63
64
# File 'lib/shapelib.rb', line 62

def side_three
  @side_three
end

#side_twoObject

Returns the value of attribute side_two.



62
63
64
# File 'lib/shapelib.rb', line 62

def side_two
  @side_two
end

Instance Method Details

#to_sObject



94
95
96
# File 'lib/shapelib.rb', line 94

def to_s
  "Triangle: #{@side_one}-#{@side_two}-#{@side_three}"
end