Skip to content

Commit

Permalink
Allow comparison with enum classes
Browse files Browse the repository at this point in the history
This addresses the issue of using enums in a case statement and also
makes the API more predictable.
  • Loading branch information
beerlington committed Oct 22, 2014
1 parent 98b74cc commit 271157f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/classy_enum/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module Collection
def <=> other
if other.is_a?(Symbol) || other.is_a?(String)
other = self.class.find(other)
elsif other.is_a?(Class)
other = other.new
end

index <=> other.index
Expand Down
1 change: 1 addition & 0 deletions spec/classy_enum/collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ClassyEnumCollection::Three < ClassyEnumCollection

context '#<=> (equality)' do
its(:first) { should == ClassyEnumCollection::One.new }
its(:first) { should == ClassyEnumCollection::One }
its(:first) { should == :one }
its(:first) { should == 'one' }
its(:first) { should_not == :two }
Expand Down

0 comments on commit 271157f

Please sign in to comment.