Friday, June 3, 2011

[Rails] Re: There must be a more elegant way to do this

On Jun 3, 1:39 pm, Valery Kvon <adda...@gmail.com> wrote:
> Well, that's other one task and not just .uniq. Magic unuseful :)
>
> You'd better to write much more complex clause:
>
> (array1 + array2 + arrayN).group_by { |instance| [instance.user_id, address_id] }.values.collect { |array| array.sort {|a,b| a.distance <=> b.distance}.first}

Now that looks like Ruby elegance - everything in one line of code!

Thanks Valery!

--
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate