adts 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/adt/constructor.rb +5 -0
- data/lib/adt/version.rb +1 -1
- data/spec/adt_spec.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa28e2d1509e8a2c7a19e507d9ed235b536361ae
|
4
|
+
data.tar.gz: 8f7ee9ff5b0a60341d1f8d7dcb51757543737e21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57503b9ef4b9fc7ee141cc3f6b88a9be8d39dfa87ed5da79c08d0fcbb14dd5335136d7f4e08f1bcf8880a8b4f55f1e60e2a7565e1df3942bf91168e857b922f2
|
7
|
+
data.tar.gz: 810adff8d25a8638b2e76e07c81cbb3d9be02330a26bb72b48e197c3c0c7619a170fe9e1f0d511f0d0689c66be7bb39bf0aed84e491675d6c449b2031e24e8c0
|
data/lib/adt/constructor.rb
CHANGED
@@ -21,6 +21,11 @@ module ADT
|
|
21
21
|
def ==(other)
|
22
22
|
other.is_a?(self.class) && #{keys.empty? ? "true" : keys.map { |key| "#{key} == other.#{key}"}.join(" && ")}
|
23
23
|
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
self.class.name.split('::').last + '(' + instance_variables.map { |i| i.to_s[1..-1] + ': ' + instance_variable_get(i).inspect }.join(', ') + ')'
|
27
|
+
end
|
28
|
+
alias inspect to_s
|
24
29
|
"
|
25
30
|
@parameters = parameters
|
26
31
|
@others = []
|
data/lib/adt/version.rb
CHANGED
data/spec/adt_spec.rb
CHANGED
@@ -44,4 +44,9 @@ describe ADT do
|
|
44
44
|
it 'uses subtyping' do
|
45
45
|
expect(Shape::Circle(1)).to be_kind_of(Shape)
|
46
46
|
end
|
47
|
+
|
48
|
+
it 'implements to_s and inspect' do
|
49
|
+
expect(Shape::Circle(1).to_s).to eq("Circle(radius: 1)")
|
50
|
+
expect(Shape::Rectangle(1, 2).inspect).to eq("Rectangle(width: 1, height: 2)")
|
51
|
+
end
|
47
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josep M. Bach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -100,3 +100,4 @@ summary: Abstract Data Types for Ruby
|
|
100
100
|
test_files:
|
101
101
|
- spec/adt_spec.rb
|
102
102
|
- spec/spec_helper.rb
|
103
|
+
has_rdoc:
|