Very nice!  The all important ||=

On Tuesday, September 1, 2015 at 11:01:57 AM UTC-4, Colin Law wrote:
>
> On 1 September 2015 at 15:41, Elizabeth McGurty <[email protected] 
> <javascript:>> wrote: 
> > And I am also super confused as to the notion of 'memorising'.  What 
> does 
> > that mean?  Kids memorise the alphabet and times tables, what does that 
> > metaphor mean in terms of Ruby and Ruby on Rails? Memorising is a 
> process of 
> > repeatedly iterating through a series that must eventually be held in 
> one's 
> > memory.  Does Rails have some neural process of educating itself in 
> neural 
> > memorising? 
>
> The test filter (which is not actually called that of course, it has a 
> name meaningful in the context of my application) does a fair amount 
> of db lookup, based on the request params, and comes up with a true or 
> false answer.  My mod is, in the test filter, to test a class variable 
> (lets call it @test_answer) and if it is nil then to run the db 
> lookups, caculate the answer true or false, save it in @test_answer 
> and return that value.  If it is not nil then I just return the value. 
> The result is that the first time it runs it does the lookup, the 
> second time it just returns the answer 
>
> In practice that just turns into something like 
> def test? 
>   @test_answer ||= do_the_lookup_and_calcs() 
> end 
>
> Colin 
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/c98708d7-9d86-40d9-90e8-2e92085cfb59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to