I wasn't talking about that specific code sample either. Long chaining of methods is an anti-pattern and we shouldn't be encouraging it. Put it in the model and decompose it.
/Jonas On Fri, Apr 16, 2010 at 4:12 PM, Evgeniy Dolzhenko <[email protected]> wrote: > Never mind that example, I made it up just to illustrate the issue > which > was that the short-circuiting had to happen in the middle of long > method > chain and I didn't want to introduce local variable just for this > optional > filtering step: > > SomeModel.some_scope.all. > group_by(&:user).<<optional filtering here >>. > map { ... }.sort_by(&:second).reverse.map(&:first) > > Though I must admit this is hardcore and happened to my only once or > twice :) > > As for "track record of getting a language extension into > ActiveSupport > if it's not being used inside the framework", here it is: > > http://github.com/rails/rails/commit/51730792ca9 > > > On Apr 16, 5:30 pm, Mislav Marohnić <[email protected]> wrote: >> On Fri, Apr 16, 2010 at 13:44, Jonas Nicklas <[email protected]>wrote: >> >> >> >> > @users = @users.select(&:admin?) if @admins_only >> > @users.sort >> >> > I think that is infinitely easier to read and understand (it took me a >> > while to figure out what the hell your code was doing). Just because >> > you *can* make everything into a one-liner in Ruby, doesn't mean you >> > *should*. >> >> I fully support Jonas. >> >> Anyway, what's the track record of getting a language extension into Active >> Support if it's not being used inside the framework? I'd say very low. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group >> athttp://groups.google.com/group/rubyonrails-core?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
