simple-identity 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  simple-identity is a Ruby library for providing simple identity methods of #eql?, #==, and #hash.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/simple-identity.png)](http://badge.fury.io/rb/simple-identity) [![Build Status](https://travis-ci.org/keita/simple-identity.png?branch=master)](https://travis-ci.org/keita/simple-identity) [![Coverage Status](https://coveralls.io/repos/keita/simple-identity/badge.png?branch=master)](https://coveralls.io/r/keita/simple-identity) [![Code Climate](https://codeclimate.com/github/keita/simple-identity.png)](https://codeclimate.com/github/keita/simple-identity)
6
+
5
7
  ## Installation
6
8
 
7
9
  $ gem install simple-identity
@@ -1,3 +1,3 @@
1
1
  module SimpleIdentity
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -3,13 +3,17 @@ require "simple-identity/version"
3
3
  module SimpleIdentity
4
4
  def eql?(other)
5
5
  return false unless other.kind_of?(self.class)
6
- instance_variables.all? do |symbol|
6
+ __identities__.all? do |symbol|
7
7
  instance_variable_get(symbol) == other.__send__(symbol.to_s[1..-1])
8
8
  end
9
9
  end
10
10
  alias :"==" :eql?
11
11
 
12
12
  def hash
13
- instance_variables.map{|symbol| instance_variable_get(symbol)}.hash
13
+ __identities__.map{|symbol| instance_variable_get(symbol)}.hash
14
+ end
15
+
16
+ def __identities__
17
+ instance_variables.select{|id| not(id.to_s.start_with?("@__"))}
14
18
  end
15
19
  end
@@ -4,16 +4,19 @@ require 'simple-identity'
4
4
  class A
5
5
  include SimpleIdentity
6
6
  attr_accessor :a, :b, :c
7
- def initialize(a, b, c)
7
+ def initialize(a, b, c, d=nil)
8
8
  @a = a
9
9
  @b = b
10
10
  @c = c
11
+ @__d__ = d
11
12
  end
12
13
  end
13
14
 
14
15
  describe "SimpleIdentity" do
15
16
  it 'should equal' do
16
17
  A.new(1,2,3).should == A.new(1,2,3)
18
+ A.new(1,2,3,4).should == A.new(1,2,3)
19
+ A.new(1,2,3,4).should == A.new(1,2,3,5)
17
20
  end
18
21
 
19
22
  it 'should not equal' do
@@ -23,6 +26,8 @@ describe "SimpleIdentity" do
23
26
 
24
27
  it 'should have same hash values' do
25
28
  A.new(1,2,3).hash.should == A.new(1,2,3).hash
29
+ A.new(1,2,3,4).hash.should == A.new(1,2,3).hash
30
+ A.new(1,2,3,4).hash.should == A.new(1,2,3,5).hash
26
31
  end
27
32
 
28
33
  it 'should have different hash values' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-identity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -93,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: 923825047101298620
96
+ hash: 4579653586567278030
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  none: false
99
99
  requirements:
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: 923825047101298620
105
+ hash: 4579653586567278030
106
106
  requirements: []
107
107
  rubyforge_project:
108
108
  rubygems_version: 1.8.24