From: Gavin Kistner Date: 2011-09-04T10:19:47+09:00 Subject: Re: Beginner needing help - Writing right-angle triangle program On Sep 3, 2011, at 2:16 PM, Adam Prescott wrote: > On Sat, Sep 3, 2011 at 4:36 PM, Gavin Kistner wrote: >> def right_triangle_sides( circumference ) >> [].tap do |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 >> end >> end > 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 and so have taken to using the very-low-impact of tap to make it more functional-style: def xyz ....tap do |foo| # do things to foo end end