Ruby on Rails Sunday, July 31, 2011

On Jul 31, 5:12 pm, 7stud -- <li...@ruby-forum.com> wrote:
>
> What do you think about this:
>
> > def current_user
> >   @current_user ||= user_from_remember_token
> > end
>
> > I see two problems with that function.  First off, that is a getter
> > function, yet it can set the @current_user variable.  Getter functions
> > should not set instance variables.  Secondly, the function directly sets
> > the @current_user variable instead of calling the current_user= setter
> > function.
>

Memoization is an extremely common practice. I find the existence of
current_user= a little odd.

Fred

> --
> Posted viahttp://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment