From: dblack@... Date: 2006-11-01T10:24:35+09:00 Subject: Re: still more relentless non-repetition Hi -- On Wed, 1 Nov 2006, ara.t.howard@noaa.gov wrote: > On Wed, 1 Nov 2006, Giles Bowkett wrote: > >> ok, I have this Rails code which I want to make more Rubyish. >> >> controller: >> >> def tracks >> @term = params[:term] || '' >> if @term.blank? >> @tracks = [] >> else >> @tracks = Track.find_by_contents @term >> end >> end > > do you really want to search twice here if tracks is called twice? > > i'm guessing you'd want > > def tracks > return @tracks unless defined? @tracks > t = params[:term] > @tracks = > if t.nil? or t.blank? nil is considered blank by blank?, so you only need the one test. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org