From: "Thomas Søndergaard" Date: 2002-03-19T23:03:52+09:00 Subject: RE: style choice > A style question for the community ... which of the following > do you prefer, and why? Or, if you prefer some third version, > what is it and why? > > def degree > return @degree if @degree > 0 > @scopes.each { | field | @degree += field.length } > @degree > end > > def degree > @scopes.each { | field | @degree += field.length } if @degree == 0 > @degree > end The second, it is: 1) (imho) slightly easier to read (it reads like you would explain it) 2) it is shorter 3) there is only one exit point You could also use inject (it's in the pick axe book, but you're a smalltalk guy aren't you?). You could even add another method like the C++ STL accumulate template function: class Array def inject(n) each { |i| n = yield(n, i) } n end def accumulate(initialVal = 0, operation = :+) inject(initialVal) { |sum, elem| sum.send(operation, elem) } end end def degree @degree = @scopes.accumulate if @degree == 0 @degree end Thomas