3 ms·
FYI: #returning is a hack that #tap supplants, and is supported in Ruby 1.8.7 natively, and is supported in Rails via ActiveSupport for older versions of Ruby.
by jherdman 17y ago
FYI: #returning is a hack that #tap supplants, and is supported in Ruby 1.8.7 natively, and is supported in Rails via ActiveSupport for older versions of Ruby.
- sunkencity 17y agoTap is also an incredibly nifty function, but they are slightly different, I hadn't thought of using tap in the same way as returning before you mentioned it. Using returning with a local variable makes for superbly readable code imho: def foo returning values = [] do values << 'bar' values << 'baz' if @iffy end end def foo [].tap do |values| values << 'bar' values << 'baz' if @iffy end end