Skip to content

Instantly share code, notes, and snippets.

@bchase
Created June 3, 2014 07:03
Show Gist options
  • Select an option

  • Save bchase/fd2b552c7b16fe7fcacd to your computer and use it in GitHub Desktop.

Select an option

Save bchase/fd2b552c7b16fe7fcacd to your computer and use it in GitHub Desktop.
def triangle(a, b, c)
Triangle.new(a, b, c).type
end
class Triangle
def initialize(a, b, c)
@sides = *a, b, c
end
attr_reader :sides
def type
if equilateral?
:equilateral
elsif isosceles?
:isosceles
else
:scalene
end
end
def equilateral?
sides.uniq.length == 1
end
def isosceles?
sides.uniq.length == 2
end
def scalene?
!equilateral? and !isosceles?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment