Skip to content
This repository
Browse code

Avoid obscure &Proc.new thing

  • Loading branch information...
commit fd68bd23b602ef2a7b038b66e787604df9192c6d 1 parent f6db31e
Jon Leighton jonleighton authored

Showing 1 changed file with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 2 activerecord/lib/active_record/scoping/named.rb
4 activerecord/lib/active_record/scoping/named.rb
@@ -171,8 +171,8 @@ def scope_attributes? # :nodoc:
171 171 # Article.published.featured.latest_article
172 172 # Article.featured.titles
173 173
174   - def scope(name, scope_options = {})
175   - extension = Module.new(&Proc.new) if block_given?
  174 + def scope(name, scope_options = {}, &block)
  175 + extension = Module.new(&block) if block
176 176
177 177 singleton_class.send(:define_method, name) do |*args|
178 178 options = scope_options.respond_to?(:call) ? unscoped { scope_options.call(*args) } : scope_options

6 comments on commit fd68bd2

Gabriel Sobrinho

I remember the &Proc.new was implemented due to performance improvement.

Are we going to remove this from rails codebase?

Jon Leighton
Owner

This is evaluated at class loading time, so it is not performance critical. We don't need performance tricks in non-crticial areas of the code.

Gabriel Sobrinho

ok! :)

Piotr Sarnacki
Collaborator

This is evaluated at class loading time, so it is not performance critical.
We don't need performance tricks in non-crticial areas of the code.

So you say rails apps will load even slower :trollface:

Jon Leighton
Owner

Yes, this one line is responsible for a 50% increase in Rails load time. I'm switching to Node.js!

Xavier Noria
Owner
fxn commented on fd68bd2

These things didn't happen with CGI.pm.

Please sign in to comment.
Something went wrong with that request. Please try again.