From: Gavin Kistner Date: 2011-09-05T00:29:05+09:00 Subject: Re: Beginner needing help - Writing right-angle triangle program On Sep 3, 2011, at 8:57 PM, 7stud -- wrote: > Gavin Kistner wrote in post #1020000: >> On Sep 3, 2011, at 2:16 PM, Adam Prescott wrote: >>> A very curious use of #tap. >> >> :) I get a lot of flack for "abusing" tap like this. I happen to find >> this pattern annoying: >> >> def xyz >> foo = ... >> # do things to foo >> foo >> end > > So when you read the thread title, "Beginner needing help", you thought > you would make some moves to impress the new guy, and show him how > unintelligible ruby is? No, that was not my intention. I don't personally find it unintelligible; indeed, other than the name of the method "tap" I find that pattern to look more elegant then a clumsy repetition of variable names. (If the method were named something like "named" or "using" or "with" my particular usage might read slightly better.) For comparison and instruction of a new user, however, here's my solution slightly changed to use what I deem to be the uglier code, and what I suppose 7stud feels is more attractive: def right_triangle_sides( circumference ) solutions = [] 1.upto(circumference-2) do |a| 1.upto(a-1) do |b| c = circumference-a-b if a*a+b*b == c*c solutions.concat( [a,b,c].permutation.to_a ) end end end solutions end