From: Andy Lowry Date: 2013-07-23T06:45:08+09:00 Subject: Re: tap { break } idiom deserves its own Kernel method? I just used the pattern again, and this time it's a much simpler example than the one I gave before. So maybe it will help. The issue is I'm getting an integer parameter from a form, and I want to store it as an integer or (if the parameter was empty) as nil. So I've written this: x = params[:distance].tap{|d| break d.empty? ? nil : d.to_i} I'd prefer to write this: x = params[:distance].pipe{|d| d.empty? ? nil : d.to_i} Without these I'd need to either repeat the params[:distance] expresion, as in the slightly damp x = params[:distance].empty? ? nil : params[:distance].to_i or I'd resort to a temp variable as in dparam = params[:distance] x = dparam.empty? ? nil : dparam.to_i Again, nothing earth moving here. I'm just partial to the pipe approach, and thought perhaps others would like it too. -- Posted via http://www.ruby-forum.com/.