From: Austin Ziegler Date: 2004-05-13T23:53:05+09:00 Subject: Re: Major Addition Bug? > Jeff Mitchell wrote on > 13 May 2004 02.59: > Coming from a background in mathematics, I have personal > affection for: > > class Float > def within?(epsilon, other) > abs(self - other) < epsilon > end > end > > EPSILON = 1e-8 > # ... > if a.within?(EPSILON, b) > # ... > > I read this as, "if a is within epsilon of b" -- a common > phrase in analysis. Mmm. I might write that as: class Float def within?(other, epsilon = 1e-8) abs(self - other) < epsilon end end It messes up the nice readability, but you don't have to type EPSILON all the time, either. Alternatively, you could do: class Float def in_epsilon?(other, epsilon = 1e-8) abs(self - other) < epsilon end end That gives you the same functionality and minimal typing, but is perhaps more readable. -austin -- austin ziegler * austin.ziegler@evault.com