Trans schrieb: > I don't really have any examples that are repleat with it, but as to > insight it's especially convenient when caching a return value: > > def x > return_on @cache[:x] > # do stuff > @cache[:x] = result_of_stuff > end > > this gets rid of an extraneous variable too b/c otherwise, the more > efficient impl. is: > > def x > r = @cache[:x] > return r if r > # do stuff > @cache[:x] = result_of_stuff > end You could also implement this as def x @cache[:x] ||= ( # do stuff result_of_stuff ) end > funny thing i just came across a similar case for break. how would you > DRY this up and get rid of 'result'? > > result = nil > files.each do > result = require file > break if result > end > if result > ... If "result" is only a flag whose value you don't need later, you could do if files.find { |file| require file } ... end Regards, Pit