Re: Question on the "common way" to code

dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
Sun, 22 Jul 2007 10:22:05 -0000

Hi --

On Sat, 21 Jul 2007, s.ross wrote:

> (3) Whatever works. Either works fine, both are ugly but necessary.
> Better, in your model do this:
>
> def full_name
>   first_name + last_name
> end
>
> Then in your view, you can just write:
>
> <%= link_to composer.full_name, composers_url(composer) %>

That still leaves the question of how to define full_name (with + or
with string interpolation), though.  Some informal benchmarking
suggests, not too surprisingly, that if you''re adding just two
strings, the adding might be faster, but if you''re adding repeatedly:

   title + " " + first_name + middle_name + last_name

then there''s a tipping point at which interpolation is faster.


David

--
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)