Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

no need for a case / when statement

  • Loading branch information...
commit 1e687e98ac4162197e33e88cb52514c59ef040d0 1 parent cab1207
@tenderlove tenderlove authored
Showing with 7 additions and 11 deletions.
  1. +7 −11 activerecord/lib/active_record/dynamic_scope_match.rb
View
18 activerecord/lib/active_record/dynamic_scope_match.rb
@@ -8,25 +8,21 @@ module ActiveRecord
# scope except that it's dynamic.
class DynamicScopeMatch
def self.match(method)
- ds_match = self.new(method)
- ds_match.scope ? ds_match : nil
+ ds_match = new(method)
+ ds_match.scope && ds_match
end
def initialize(method)
- @scope = true
- case method.to_s
- when /^scoped_by_([_a-zA-Z]\w*)$/
+ @scope = nil
+ if method.to_s =~ /^scoped_by_([_a-zA-Z]\w*)$/
names = $1
- else
- @scope = nil
+ @scope = true
end
+
@attribute_names = names && names.split('_and_')
end
attr_reader :scope, :attribute_names
-
- def scope?
- !@scope.nil?
- end
+ alias :scope? :scope
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.