strukt 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/strukt.rb +10 -1
- data/spec/strukt_spec.rb +39 -0
- metadata +2 -2
data/lib/strukt.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class Strukt
|
2
|
-
VERSION = "0.0.
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
|
4
4
|
include Enumerable
|
5
5
|
|
@@ -19,6 +19,14 @@ class Strukt
|
|
19
19
|
other.is_a?(self.class) && to_hash == other.to_hash
|
20
20
|
end
|
21
21
|
|
22
|
+
def eql?(other)
|
23
|
+
self == other
|
24
|
+
end
|
25
|
+
|
26
|
+
def hash
|
27
|
+
to_hash.hash
|
28
|
+
end
|
29
|
+
|
22
30
|
def to_hash
|
23
31
|
{}.tap { |h| self.class::MEMBERS.each { |m| h[m] = send(m) } }
|
24
32
|
end
|
@@ -29,3 +37,4 @@ class Strukt
|
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
40
|
+
|
data/spec/strukt_spec.rb
CHANGED
@@ -53,7 +53,46 @@ describe Strukt do
|
|
53
53
|
expect(bob).not_to eq(alien_bob)
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe "#eql" do
|
58
|
+
it "is true if all the parameters are ==" do
|
59
|
+
bob_1 = Person.new(:name => "Bob", :age => 50)
|
60
|
+
bob_2 = Person.new(:name => "Bob", :age => 50)
|
61
|
+
|
62
|
+
expect(bob_1).to eql(bob_2)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "is false if any attributes are not #==" do
|
66
|
+
bob = Person.new(:name => "Bob", :age => 50)
|
67
|
+
ted = Person.new(:name => "Ted", :age => 50)
|
68
|
+
|
69
|
+
expect(bob).not_to eql(ted)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "is false if the other object is not of the same class" do
|
73
|
+
bob = Person.new(:name => "Bob", :age => 50)
|
74
|
+
alien_bob = Struct.new(:name, :age).new("Bob", 50)
|
75
|
+
|
76
|
+
expect(bob).not_to eql(alien_bob)
|
77
|
+
end
|
78
|
+
end
|
56
79
|
|
80
|
+
describe "#hash" do
|
81
|
+
it "is stable" do
|
82
|
+
bob_1 = Person.new(:name => "BOB")
|
83
|
+
bob_2 = Person.new(:name => "BOB")
|
84
|
+
|
85
|
+
expect(bob_1.hash).to eq(bob_2.hash)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "varies with the parameters" do
|
89
|
+
bob = Person.new(:name => "Bob", :age => 50)
|
90
|
+
ted = Person.new(:name => "Ted", :age => 50)
|
91
|
+
|
92
|
+
expect(bob.hash).not_to eql(ted.hash)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
57
96
|
describe "::MEMBERS" do
|
58
97
|
it "is the list of member variables" do
|
59
98
|
expect(Person::MEMBERS).to eq([:name, :age])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strukt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|