returning(...) ?
Stephen Caudill
scaudill at gmail.com
Tue Sep 4 19:37:24 EDT 2007
On Sep 4, 2007, at 4:46 PM, Brian Candler wrote:
>
> Before:
>
> def <=>(entry)
> returning((entry.quality <=> quality).to_s) do |c|
> c.replace((index <=> entry.index).to_s) if c == '0'
> end.to_i
> end
>
> After:
>
> def <=>(entry)
> c = (entry.quality <=> quality).to_s
> c.replace((index <=> entry.index).to_s) if c == '0'
> c.to_i
> end
Ah... That'd be me. I'm still fond of the k-combinator, but not so
fond of it that I can't see a misuse these days :) The .to_s and
then subsequent .to_i were merely facilitators to being able to use
returning. That snippet would probably be best rewritten as:
def <=>(entry)
c = entry.quality <=> quality
c = index <=> entry.index if c == 0
c
end
specs still pass with that change made.
--
Stephen Caudill (voxdolo)
More information about the Merb-devel
mailing list