module PicheCoolGem::TriangleType
Public Class Methods
calculate(a, b, c)
click to toggle source
# File lib/piche_cool_gem/triangle_type.rb, line 3 def self.calculate(a, b, c) raise ArgumentError.new("Must provide numbers") if any_args_non_number?(a, b, c) raise ArgumentError.new("0 length sides not allowed") if any_args_zero?(a, b, c) a_squared = a**2 b_squared = b**2 c_squared = c**2 left_side = a_squared + b_squared if a == b && b == c 'Equilateral' elsif left_side == c_squared 'Right' elsif left_side > c_squared 'Acute' elsif left_side < c_squared 'Obtuse' end end
Private Class Methods
any_args_non_number?(*args)
click to toggle source
# File lib/piche_cool_gem/triangle_type.rb, line 29 def self.any_args_non_number?(*args) args.any? { |a| !a.is_a? Numeric } end
any_args_zero?(*args)
click to toggle source
# File lib/piche_cool_gem/triangle_type.rb, line 25 def self.any_args_zero?(*args) args.any?(&:zero?) end