Skip to content

Commit

Permalink
[Platform] Make instances usable as Hash keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Apr 15, 2014
1 parent e1493dc commit f8c7320
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

##### Enhancements

* Make Platform instances usable as Hash keys.
[Eloy Durán](https://github.com/alloy)
[#109](https://github.com/CocoaPods/Core/pull/109)

* Accept new sources for Pods when they are just redirects of the old one.
[Boris Bügling](https://github.com/neonichu)
[#101](https://github.com/CocoaPods/Core/issues/101)
Expand Down
12 changes: 12 additions & 0 deletions lib/cocoapods-core/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ def ==(other)
end
end

# (see #==)
alias_method :eql?, :==

# Hashes the instance by the platform name and deployment target.
#
# This adds support to make instances usable as Hash keys.
#
# @!visibility private
def hash
name.hash ^ deployment_target.hash
end

# Checks whether a platform supports another one.
#
# In the context of operating system SDKs, a platform supports another
Expand Down
12 changes: 12 additions & 0 deletions spec/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ module Pod
Platform.new(:ios, '5.0').requires_legacy_ios_archs?.should.be.false
end

it 'is usable as hash keys' do
ios = Platform.new(:ios)
osx = Platform.new(:osx)
ios6 = Platform.new(:ios, '6.0')
ios61 = Platform.new(:ios, '6.1')
hash = { ios => ios, osx => osx, ios6 => ios6, ios61 => ios61 }
hash[Platform.new(:ios)].should.be.eql ios
hash[Platform.new(:osx)].should.be.eql osx
hash[Platform.new(:ios, '6.0')].should.be.eql ios6
hash[Platform.new(:ios, '6.1')].should.be.eql ios61
end

end

describe 'Supporting other platforms' do
Expand Down

0 comments on commit f8c7320

Please sign in to comment.