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: , , , .

Leave a Comment

hidden

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


Categories

posts[:recent]

episodes[:recycled]

@@name = PRAYAS

Step down at my blog with your ideas,comments,suggestions on Ruby,RoR,Ajax or Web2.0.You may reach me at
infostall@gmail.com

find_by_tags

Links

visitors[:since_Mar'08]

free web counter

Spam Blocked

Feeds

Meta

RSS Prayas here