Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Added support for value to be Enumerable #607

merged 1 commit into from

3 participants


I wanted to the ability to pass in a Set to the conditions if I had a large set of numbers and wanted the performance, but since you only checked against Range and Array, I couldn't do this.

@Sija Sija referenced this pull request from a commit in Sija/cancan
@Sija Sija Merged PR #607 5266613

[verified] Seems like an excellent patch.

@ryanb ryanb merged commit 6e8bc85 into from

thanks @jeremyf!

Thanks for merging it in @ryanb. When do you expect to create a new tag and push to rubygems?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2012
  1. @Aryk
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 2 deletions.
  1. +1 −1  lib/cancan/rule.rb
  2. +9 −1 spec/cancan/ability_spec.rb
2  lib/cancan/rule.rb
@@ -111,7 +111,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
!attribute.nil? && matches_conditions_hash?(attribute, value)
- elsif value.kind_of?(Array) || value.kind_of?(Range)
+ elsif value.kind_of?(Enumerable)
value.include? attribute
attribute == value
10 spec/cancan/ability_spec.rb
@@ -249,7 +249,15 @@
@ability.can?(:read, 1..5).should be_true
@ability.can?(:read, 4..6).should be_false
+ it "should accept a set as a condition value" do
+ mock(object_with_foo_2 = { 2 }
+ mock(object_with_foo_3 = { 3 }
+ @ability.can :read, Object, :foo => [1, 2, 5].to_set
+ @ability.can?(:read, object_with_foo_2).should be_true
+ @ability.can?(:read, object_with_foo_3).should be_false
+ end
it "should not match subjects return nil for methods that must match nested a nested conditions hash" do
mock(object_with_foo = { :bar }
@ability.can :read, Array, :first => { :foo => :bar }
Something went wrong with that request. Please try again.