code optimization
June 18, 2008 at 11:09 am Leave a comment
if params[:a].nil?
if params[:b].nil?
"999"
else
params[:b]
end
else
params[:a]
end
the same can be written using ternary operator
@a1 = params[:a].nil? ? params[:b].nil? ? ’999′ : params[:b] :params[:a]
But you know RoR is so powerful…..
@a1 = params[:a] ||= params[:b] ||= ’999′
[Background support : Ashish S.]
Entry filed under: coding, Rails. Tags: code, operator, optimization, ||=.



Trackback this post | Subscribe to the comments via RSS Feed