Time to learn Ruby

What better time is there to learn ruby than on one’s vacation? I’m considering using it to develop a very exciting secret project involving web typography. Like many programmers, I’m going through the ruby koans Lose Weight Exercises to get used to using the language.

about_triangle_project.rb

Sofar, my favorite problems are the about_triangle_project.rb and about_triangle_project2.rb problems. Here’s my solution:

def triangle(a, b, c)
	# important for efficient triangle testing
	ar = [a,b,c].sort

	# test for impossible triangles from sorted array of sides
	raise TriangleError, "Impossible!" unless
		ar[0] > 0 and ar[0] + ar[1] > ar[2]

	# identify triangle type with some stringy magic
	case [a,b,c].uniq.size
		when 1 then :equilateral
		when 2 then :isosceles
		when 3 then :scalene
	end
end

Isn’t unless a fun operator?
(more…)