adts 0.0.2 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b992248512bdf339ed09533686f885cdf32aa383
4
- data.tar.gz: e593219e866f7d467262ed87e12e60e4f34940d3
3
+ metadata.gz: 4162fbb5e18982b4036110f988f631d07eed48b9
4
+ data.tar.gz: d96dd1f30153023ea1f390f6d0a4351c15283c6a
5
5
  SHA512:
6
- metadata.gz: 72186a0a9d0e18aa592f26c58910bc66ccba042d02139703b263dd35d0d0596e4f28e15a69bbd3f64a8ccf3d35df0b5892660c1c1878aab76c2c794b7792fc35
7
- data.tar.gz: 27bffe2175227aaaca19af3026a6eeec3490f45382a716f5dc10044e2f91a4d49d9e21944318fd5e6cdd234de7eb67a770b80e23563ba367d49211dc8eefd1b9
6
+ metadata.gz: 04d46f79094e626edd1369bb192db2708108eb15766e8117f553d31233214c70ab260bc1f31d279119ecc7103c332a6635a99a6f25278b2ba80c8f61f5d3c87c
7
+ data.tar.gz: b50b446aaf64d21917f107467dd6a15891ddba0a284b128d61c4a0bd7886be296f46ead77e1903e023472d017611818378f19f1658b4c845916acc73a8aef586
data/README.md CHANGED
@@ -11,9 +11,9 @@ require 'adts'
11
11
 
12
12
  Shape = ADT do
13
13
  Void() |
14
- Square(width: Fixnum) |
15
- Rectangle(width: Fixnum, height: Fixnum) |
16
- Circle(radius: Fixnum) {
14
+ Square(width: Numeric) |
15
+ Rectangle(width: Numeric, height: Numeric) |
16
+ Circle(radius: Numeric) {
17
17
  def area
18
18
  Math::PI * radius * radius
19
19
  end
@@ -11,8 +11,10 @@ module ADT
11
11
  attr_reader #{keys.map { |n| ":#{n}" }.join(', ')}
12
12
 
13
13
  def initialize(#{keys.join(", ")})
14
- types = [#{keys.join(", ")}].map(&:class)
15
- raise TypeError, 'Types mismatch: given ' + types.join(', ') + ', expected #{types.join(", ")}' unless types == [#{types.join(", ")}]
14
+ arg_types = [#{keys.join(", ")}].map(&:class)
15
+ unless arg_types.zip([#{types.join(", ")}]).all? { |arg_type, type| arg_type <= type }
16
+ raise TypeError, 'Types mismatch: given ' + arg_types.join(', ') + ', expected #{types.join(", ")}'
17
+ end
16
18
  #{keys.empty? ? "" : keys.map{ |n| "@#{n}" }.join(',') + " = " + keys.join(", ")}
17
19
  end
18
20
 
@@ -1,3 +1,3 @@
1
1
  module ADT
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1 @@
1
+ require 'adt'
@@ -1,10 +1,10 @@
1
1
  require 'rspec'
2
- require 'adt'
2
+ require 'adts'
3
3
 
4
4
  Shape = ADT do
5
5
  Void() |
6
6
  Square(width: Fixnum) |
7
- Rectangle(width: Fixnum, height: Fixnum) |
7
+ Rectangle(width: Numeric, height: Numeric) |
8
8
  Circle(radius: Fixnum) {
9
9
  def area
10
10
  Math::PI * radius * radius
@@ -22,6 +22,11 @@ describe ADT do
22
22
  expect { Shape::Square("foo") }.to raise_exception(TypeError)
23
23
  end
24
24
 
25
+ it 'allows inherited types' do
26
+ expect { Shape::Rectangle(23, 45.1) }.to_not raise_exception
27
+ expect { Shape::Rectangle("foo", "bar") }.to raise_exception(TypeError)
28
+ end
29
+
25
30
  it 'implements equality by type and value' do
26
31
  expect(Shape::Square(23)).to eq(Shape::Square(23))
27
32
  expect(Shape::Circle(23)).to_not eq(Shape::Square(23))
@@ -39,4 +44,4 @@ describe ADT do
39
44
  it 'uses subtyping' do
40
45
  expect(Shape::Circle(1)).to be_kind_of(Shape)
41
46
  end
42
- end
47
+ 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.0.2
4
+ version: 0.1.0
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: 2014-11-10 00:00:00.000000000 Z
11
+ date: 2014-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -70,6 +70,7 @@ files:
70
70
  - lib/adt.rb
71
71
  - lib/adt/constructor.rb
72
72
  - lib/adt/version.rb
73
+ - lib/adts.rb
73
74
  - spec/adt_spec.rb
74
75
  - spec/spec_helper.rb
75
76
  homepage: http://blog.txus.io/adts