i wouldn''t lose any sleep over something like this regarding resource
consumption. it really doesn''t matter.
even so,
>> id = user.id
=> 1>> user.id.object_id
=> 3>> id.object_id
=> 3
They are the same anyway, so why add the extra line of code if it
really doesn''t do anything?
Personally, @user.id is what i would use. Why? Because if I were
reading your code, everywhere you use @user.id, I would know exactly
what you meant. Using just ''id'' can be a little ambiguous and
can
lead to possible confusion as to intent. Even if you use
''user_id'',
see the previous paragraph.
I would be more concerned about resource consumption if you were to
have a method which made a complicated calculation, in that case I
would use your example.
result_of_complicated_calculation = @obj.complicated_calculation
# use result_of_complicated_calculation in the rest of the code
Chris
On 12/21/06, Aryk Grosz
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> In my app, if I have to call @user.id more than once, ill do
>
> id=@user.id
>
> Then in the code, ill use "id" everywhere that I need it. Is this
> unneccessary? Should I just be using @user.id?
>
> In other words, does the ".id" method call more resource
consuming than
> passing it into a variable and does it matter?
>
> -Aryk
>
> --
> Posted via http://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---