3 ms·
Tap 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.
by sunkencity 17y ago
Tap 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