Skip to content
Browse files

constructor should not do so much work; avoid allocating object if po…

…ssible
  • Loading branch information...
1 parent 409bd22 commit ecbfed2f8347a0c6017862a2204da1f23ed44084 @tenderlove tenderlove committed Sep 27, 2010
Showing with 5 additions and 10 deletions.
  1. +5 −10 activerecord/lib/active_record/dynamic_scope_match.rb
View
15 activerecord/lib/active_record/dynamic_scope_match.rb
@@ -8,18 +8,13 @@ module ActiveRecord
# scope except that it's dynamic.
class DynamicScopeMatch
def self.match(method)
- ds_match = new(method)
- ds_match.scope && ds_match
+ return unless method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/
+ new(true, $1 && $1.split('_and_'))
end
- def initialize(method)
- @scope = nil
- if method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/
- names = $1
- @scope = true
- end
-
- @attribute_names = names && names.split('_and_')
+ def initialize(scope, attribute_names)
+ @scope = scope
+ @attribute_names = attribute_names
end
attr_reader :scope, :attribute_names

0 comments on commit ecbfed2

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