code optimization
June 18, 2008
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: Rails, coding. Tags: code, optimization, operator, ||=.
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed