platypus 1.0.1 → 1.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 +7 -0
- data/HISTORY.md +41 -0
- data/LICENSE.txt +23 -0
- data/README.md +122 -0
- data/demo/01_intro.md +2 -0
- data/demo/02_typecast.md +29 -0
- data/demo/03_type.md +33 -0
- data/{qed/04_overload.rdoc → demo/04_overload.md} +26 -26
- data/demo/applique/env.rb +1 -0
- data/lib/platypus/core_ext.rb +2 -1
- data/lib/platypus/type.rb +1 -1
- data/lib/platypus/typecast.rb +1 -1
- data/lib/platypus/version.rb +1 -1
- metadata +42 -44
- data/.ruby +0 -44
- data/HISTORY.rdoc +0 -20
- data/NOTES.rdoc +0 -14
- data/README.rdoc +0 -108
- data/qed/01_intro.rdoc +0 -2
- data/qed/02_typecast.rdoc +0 -29
- data/qed/03_type.rdoc +0 -32
- data/test/test_overload.rb +0 -173
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a5a8cc9e4c9edf9bb0f2103eb75986e4db58a520ad16989883411fa55be0fde3
|
|
4
|
+
data.tar.gz: bd9f3a59f53981bd6434b17aad52750a3c52509bc1bd227fadd804e4f0d6117b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2c2b06fb3ab9056d95638a03e86d1e208c58384958fd18385fa54248c2f25566d27b8dde8714c5fef8845078f95cc8e95a8c95be3c85e41bf50d84c559fe88c6
|
|
7
|
+
data.tar.gz: 833a810527e7421a3ec6536ab6ec2856169580048ed812d8ca32f58b268c19f0e1aeb84eefea4db491add05d6f1e31176d18efe1a2d5e59a9d7ab6641dca11ba
|
data/HISTORY.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Release History
|
|
2
|
+
|
|
3
|
+
## 1.1.0 / 2026-04-03
|
|
4
|
+
|
|
5
|
+
Maintenance release. Modernized project tooling.
|
|
6
|
+
|
|
7
|
+
Changes:
|
|
8
|
+
|
|
9
|
+
* Replace custom Indexer system with standard gemspec.
|
|
10
|
+
* Replace Travis CI with GitHub Actions.
|
|
11
|
+
* Add Rakefile.
|
|
12
|
+
* Update URLs to HTTPS.
|
|
13
|
+
* Clean up obsolete files and .gitignore.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## 1.0.2 / 2011-10-22
|
|
17
|
+
|
|
18
|
+
This release fixes a bug that preventd Kernel#case? from being defined.
|
|
19
|
+
|
|
20
|
+
Changes:
|
|
21
|
+
|
|
22
|
+
* Remove Kernel#case? def condition [bug].
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 1.0.1 / 2011-10-19
|
|
26
|
+
|
|
27
|
+
This release simply refreshes the project build script.
|
|
28
|
+
Functionality hasn't changed at all.
|
|
29
|
+
|
|
30
|
+
Changes:
|
|
31
|
+
|
|
32
|
+
* Administrative details only.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## 1.0.0 / 2009-07-07
|
|
36
|
+
|
|
37
|
+
This is the initial stand-alone release of Platypus.
|
|
38
|
+
|
|
39
|
+
Changes:
|
|
40
|
+
|
|
41
|
+
* Happy Birthday!
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
License:: BSD-2-Clause
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
7
|
+
this list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
documentation and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
14
|
+
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
+
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
16
|
+
COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
17
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
18
|
+
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
19
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
20
|
+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
21
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
22
|
+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
23
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Platypus
|
|
2
|
+
|
|
3
|
+
[Source Code](https://github.com/rubyworks/platypus) |
|
|
4
|
+
[Report Issue](https://github.com/rubyworks/platypus/issues)
|
|
5
|
+
|
|
6
|
+
[](https://rubygems.org/gems/platypus)
|
|
7
|
+
[](https://github.com/rubyworks/platypus/actions/workflows/test.yml)
|
|
8
|
+
|
|
9
|
+
<b>Platypus provides a generalized type conversion system,
|
|
10
|
+
method overloading and psuedo-classes for the Ruby programming
|
|
11
|
+
language.</b>
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Overview
|
|
15
|
+
|
|
16
|
+
Type conversion work like a rational duck might expect.
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
"1234".to(Float) => 1234.0 (Float)
|
|
20
|
+
|
|
21
|
+
Time.from("6:30") => 1234.0 (Time)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
You can of course define your own.
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
class X
|
|
28
|
+
typecast String do |x|
|
|
29
|
+
"#{x}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
To overload a method, mixin the Overloadable module and use the #overload (or #sig)
|
|
35
|
+
method to define new functionality based on a specified type interface.
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
class X
|
|
39
|
+
include Overloadable
|
|
40
|
+
|
|
41
|
+
def f
|
|
42
|
+
"f"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
sig Integer
|
|
46
|
+
def f(i)
|
|
47
|
+
"f#{i}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
sig String, String
|
|
51
|
+
def f(s1, s2)
|
|
52
|
+
[s1, s2].join('+')
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
x = X.new
|
|
57
|
+
|
|
58
|
+
x.f #=> "f"
|
|
59
|
+
x.f(1) #=> "f1"
|
|
60
|
+
x.f("A","B") #=> "A+B"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Finally, the Platypus gives you the Type superclass (aka pseudo-classes).
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
class KiloType < Type
|
|
67
|
+
x % 1000 == 0
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
KiloType === 1000
|
|
71
|
+
KiloType === 2000
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
To learn more about using Platypus see the [Demonstrundum](http://rubyworks.github.com/platypus/docs/demo).
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
## Installation
|
|
78
|
+
|
|
79
|
+
To install with RubyGems simply open a console and type:
|
|
80
|
+
|
|
81
|
+
$ gem install platypus
|
|
82
|
+
|
|
83
|
+
Or add it as a dependency to your Gemfile.
|
|
84
|
+
|
|
85
|
+
gem "platypus"
|
|
86
|
+
|
|
87
|
+
Old school site installation can be achieved with Setup.rb (gem install setup),
|
|
88
|
+
then download the tarball package and type:
|
|
89
|
+
|
|
90
|
+
$ tar -xvzf platypus-1.0.0.tgz
|
|
91
|
+
$ cd platypus-1.0.0
|
|
92
|
+
$ setup.rb all
|
|
93
|
+
|
|
94
|
+
Windows users use 'ruby setup.rb all'.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## Authors
|
|
98
|
+
|
|
99
|
+
* Thomas Sawyer (trans)
|
|
100
|
+
* Jonas Pfenniger
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Copying
|
|
104
|
+
|
|
105
|
+
Copyright (c) 2010 Rubyworks
|
|
106
|
+
|
|
107
|
+
This program is ditributed unser the terms of the *FreeBSD* license.
|
|
108
|
+
|
|
109
|
+
See LICENSE.txt file for details.
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
<br/><br/>
|
|
113
|
+
|
|
114
|
+
_ ___
|
|
115
|
+
/ \ / \
|
|
116
|
+
\. |: cc| .---------.
|
|
117
|
+
(.|:,---, < Feel the \
|
|
118
|
+
(.|: \ c| \ POWER!!! /
|
|
119
|
+
(. y-' '--------'
|
|
120
|
+
\ _ /
|
|
121
|
+
m m
|
|
122
|
+
|
data/demo/01_intro.md
ADDED
data/demo/02_typecast.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
## Type Casting
|
|
2
|
+
|
|
3
|
+
Require the casting library.
|
|
4
|
+
|
|
5
|
+
require 'platypus/typecast'
|
|
6
|
+
|
|
7
|
+
Define a couple of typecasts.
|
|
8
|
+
|
|
9
|
+
class ::String
|
|
10
|
+
typecast ::Regexp do |string|
|
|
11
|
+
/#{string}/
|
|
12
|
+
end
|
|
13
|
+
typecast ::Regexp, :multiline do |string|
|
|
14
|
+
/#{string}/m
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
::String.typecast ::Integer do |string|
|
|
19
|
+
Integer(string)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
See that they work.
|
|
23
|
+
|
|
24
|
+
::Regexp.from("ABC").assert == /ABC/
|
|
25
|
+
|
|
26
|
+
And again.
|
|
27
|
+
|
|
28
|
+
"123".to(::Integer).assert == 123
|
|
29
|
+
|
data/demo/03_type.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
## Pseudo-Types
|
|
2
|
+
|
|
3
|
+
Require the library.
|
|
4
|
+
|
|
5
|
+
require 'platypus/type'
|
|
6
|
+
|
|
7
|
+
Now we can create types which are psuedo-classes.
|
|
8
|
+
|
|
9
|
+
class KiloType < Type
|
|
10
|
+
condition do |x|
|
|
11
|
+
x.case? Integer
|
|
12
|
+
x.kind_of?(Integer)
|
|
13
|
+
x.respond_to?(:succ)
|
|
14
|
+
x > 1000
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
KiloType.assert === 2000
|
|
19
|
+
KiloType.refute === 999
|
|
20
|
+
|
|
21
|
+
Using the convenience #x method.
|
|
22
|
+
|
|
23
|
+
class MegaType < Type
|
|
24
|
+
x.case? Integer
|
|
25
|
+
x.kind_of?(Integer)
|
|
26
|
+
x.respond_to?(:succ)
|
|
27
|
+
x > 1000000
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
MegaType.refute === 999999
|
|
31
|
+
MegaType.assert === 20000000
|
|
32
|
+
|
|
33
|
+
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
## Overloadable
|
|
2
2
|
|
|
3
3
|
The Overloadable mixin provides a means for overloading
|
|
4
4
|
methods based in method signature using an elegant syntax.
|
|
5
5
|
To demonstrate, we first need to load the library.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
require 'platypus/overload'
|
|
8
8
|
|
|
9
9
|
Now we can define a class that utilizes it.
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
class X
|
|
12
|
+
include Overloadable
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
sig String, String
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
def x(str1, str2)
|
|
17
|
+
str1.assert.is_a?(String)
|
|
18
|
+
str2.assert.is_a?(String)
|
|
19
|
+
end
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
sig Integer, Integer
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
def x(int1, int2)
|
|
24
|
+
int1.assert.is_a?(Integer)
|
|
25
|
+
int2.assert.is_a?(Integer)
|
|
26
|
+
end
|
|
26
27
|
end
|
|
27
|
-
end
|
|
28
28
|
|
|
29
29
|
As you can see will placed assertions directly into our methods
|
|
30
30
|
definitions. We simply need to run an exmaple of each definition to
|
|
31
31
|
see that it worked.
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
x = X.new
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
x.x("Hello", "World")
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
x.x(100, 200)
|
|
38
38
|
|
|
39
39
|
But what happens if the signiture is not matched? Either an ArgumentError will
|
|
40
40
|
be raised.
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
expect ArgumentError do
|
|
43
|
+
x.x("Hello", 200)
|
|
44
|
+
end
|
|
45
45
|
|
|
46
46
|
Or it will fallback to a non-signiature definition, if one is defined.
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
class X
|
|
50
|
+
def x(obj1, obj2)
|
|
51
|
+
obj1.refute.is_a?(Integer)
|
|
52
|
+
obj2.refute.is_a?(String)
|
|
53
|
+
end
|
|
53
54
|
end
|
|
54
|
-
end
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
x.x("Hello", 200)
|
|
57
57
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'ae'
|
data/lib/platypus/core_ext.rb
CHANGED
data/lib/platypus/type.rb
CHANGED
|
@@ -24,7 +24,7 @@ require 'platypus/core_ext'
|
|
|
24
24
|
#
|
|
25
25
|
# While TypeCasts are not actual types in the sense they
|
|
26
26
|
# are not actual classes. They can be used for conversion
|
|
27
|
-
# by defining a "from_
|
|
27
|
+
# by defining a "from_<class>" class method. In doing so
|
|
28
28
|
# you should make sure the result of the conversion conforms
|
|
29
29
|
# to the typecast. You can use the TypeCast.validate method
|
|
30
30
|
# to make that a bit easier. For instance:
|
data/lib/platypus/typecast.rb
CHANGED
data/lib/platypus/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,86 +1,84 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: platypus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 1.1.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Thomas Sawyer
|
|
9
8
|
- Jonas Pfenniger
|
|
10
|
-
autorequire:
|
|
11
9
|
bindir: bin
|
|
12
10
|
cert_chain: []
|
|
13
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
14
12
|
dependencies:
|
|
15
13
|
- !ruby/object:Gem::Dependency
|
|
16
|
-
name:
|
|
17
|
-
requirement:
|
|
18
|
-
none: false
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
19
16
|
requirements:
|
|
20
|
-
- -
|
|
17
|
+
- - ">="
|
|
21
18
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '
|
|
19
|
+
version: '13'
|
|
23
20
|
type: :development
|
|
24
21
|
prerelease: false
|
|
25
|
-
version_requirements:
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '13'
|
|
26
27
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
28
|
-
requirement:
|
|
29
|
-
none: false
|
|
28
|
+
name: minitest
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '5'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
|
-
version_requirements:
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '5'
|
|
37
41
|
description: Provides a complete double-dispatch type conversion system, method overloadability
|
|
38
|
-
and
|
|
39
|
-
email:
|
|
42
|
+
and pseudo-classes.
|
|
43
|
+
email:
|
|
44
|
+
- transfire@gmail.com
|
|
40
45
|
executables: []
|
|
41
46
|
extensions: []
|
|
42
|
-
extra_rdoc_files:
|
|
43
|
-
- HISTORY.rdoc
|
|
44
|
-
- README.rdoc
|
|
45
|
-
- NOTES.rdoc
|
|
47
|
+
extra_rdoc_files: []
|
|
46
48
|
files:
|
|
47
|
-
- .
|
|
49
|
+
- HISTORY.md
|
|
50
|
+
- LICENSE.txt
|
|
51
|
+
- README.md
|
|
52
|
+
- demo/01_intro.md
|
|
53
|
+
- demo/02_typecast.md
|
|
54
|
+
- demo/03_type.md
|
|
55
|
+
- demo/04_overload.md
|
|
56
|
+
- demo/applique/env.rb
|
|
57
|
+
- lib/platypus.rb
|
|
48
58
|
- lib/platypus/core_ext.rb
|
|
49
59
|
- lib/platypus/overload.rb
|
|
50
60
|
- lib/platypus/type.rb
|
|
51
61
|
- lib/platypus/typecast.rb
|
|
52
62
|
- lib/platypus/version.rb
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
-
|
|
56
|
-
|
|
57
|
-
- qed/04_overload.rdoc
|
|
58
|
-
- test/test_overload.rb
|
|
59
|
-
- HISTORY.rdoc
|
|
60
|
-
- README.rdoc
|
|
61
|
-
- NOTES.rdoc
|
|
62
|
-
homepage: http://rubyworks.github.com/platypus
|
|
63
|
-
licenses: []
|
|
64
|
-
post_install_message:
|
|
63
|
+
homepage: https://github.com/rubyworks/platypus
|
|
64
|
+
licenses:
|
|
65
|
+
- BSD-2-Clause
|
|
66
|
+
metadata: {}
|
|
65
67
|
rdoc_options: []
|
|
66
68
|
require_paths:
|
|
67
69
|
- lib
|
|
68
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
|
-
none: false
|
|
70
71
|
requirements:
|
|
71
|
-
- -
|
|
72
|
+
- - ">="
|
|
72
73
|
- !ruby/object:Gem::Version
|
|
73
|
-
version: '
|
|
74
|
+
version: '3.1'
|
|
74
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
-
none: false
|
|
76
76
|
requirements:
|
|
77
|
-
- -
|
|
77
|
+
- - ">="
|
|
78
78
|
- !ruby/object:Gem::Version
|
|
79
79
|
version: '0'
|
|
80
80
|
requirements: []
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
signing_key:
|
|
84
|
-
specification_version: 3
|
|
81
|
+
rubygems_version: 3.6.9
|
|
82
|
+
specification_version: 4
|
|
85
83
|
summary: Riding on Types with Ruby
|
|
86
84
|
test_files: []
|
data/.ruby
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
authors:
|
|
3
|
-
- name: Thomas Sawyer
|
|
4
|
-
- name: Jonas Pfenniger
|
|
5
|
-
copyrights:
|
|
6
|
-
- holder: Thomas Sawyer
|
|
7
|
-
year: '2004'
|
|
8
|
-
license: BSD-2-Clause
|
|
9
|
-
replacements: []
|
|
10
|
-
conflicts: []
|
|
11
|
-
requirements:
|
|
12
|
-
- name: detroit
|
|
13
|
-
groups:
|
|
14
|
-
- build
|
|
15
|
-
development: true
|
|
16
|
-
- name: qed
|
|
17
|
-
groups:
|
|
18
|
-
- test
|
|
19
|
-
development: true
|
|
20
|
-
dependencies: []
|
|
21
|
-
repositories:
|
|
22
|
-
- uri: http://rubyworks.github.com/platypus.git
|
|
23
|
-
scm: git
|
|
24
|
-
name: upstream
|
|
25
|
-
resources:
|
|
26
|
-
home: http://rubyworks.github.com/platypus
|
|
27
|
-
code: http://github.com/rubyworks/platypus
|
|
28
|
-
mail: http://googlegroups/group/rubyworks-mailinglist
|
|
29
|
-
load_path:
|
|
30
|
-
- lib
|
|
31
|
-
extra: {}
|
|
32
|
-
source:
|
|
33
|
-
- Profile
|
|
34
|
-
alternatives: []
|
|
35
|
-
revision: 0
|
|
36
|
-
version: 1.0.1
|
|
37
|
-
name: platypus
|
|
38
|
-
title: Platypus
|
|
39
|
-
summary: Riding on Types with Ruby
|
|
40
|
-
created: '2004-01-01'
|
|
41
|
-
description: Provides a complete double-dispatch type conversion system, method overloadability
|
|
42
|
-
and psuedo-classes.
|
|
43
|
-
organization: RubyWorks
|
|
44
|
-
date: '2011-10-20'
|
data/HISTORY.rdoc
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
= Release History
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
== 1.0.1 / 2011-10-19
|
|
5
|
-
|
|
6
|
-
This release simply refreshes the project build script.
|
|
7
|
-
Functionality hasn't changed at all.
|
|
8
|
-
|
|
9
|
-
Changes:
|
|
10
|
-
|
|
11
|
-
* Administrative details only.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
== 1.0.0 / 2009-07-07
|
|
15
|
-
|
|
16
|
-
This is the initial stand-alone release of Platypus.
|
|
17
|
-
|
|
18
|
-
Changes:
|
|
19
|
-
|
|
20
|
-
* Happy Birthday!
|
data/NOTES.rdoc
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
= Developer's Notes
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
== 2011-10-19 | Name of Project
|
|
5
|
-
|
|
6
|
-
This project used to be call Typecast. Maybe that was better than the "silly"
|
|
7
|
-
Platypus name? But, then again, "typecast" doesn't quite cover everything this
|
|
8
|
-
library does.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
== 2010-05-27 | Alias for +Overloadable#overload+
|
|
12
|
-
|
|
13
|
-
I am not sure if I like +con+, +sig+ or +over+ better as a short alias for +overload+. I thought of +con+ becuase of it's double meaning as Latin for 'with' and as an abbreviation for 'conditional'. But it seems esoteric in practice, perhaps b/c it would be too general a term if we were programming in Spanish. While +over+ probably makes the most sense in terms of being an abbreviated form of +overload+, +sig+ is the same number of characters as +def+ and conveys some additional semantics which applies to method overloading --the *signature*.
|
|
14
|
-
|
data/README.rdoc
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
= Platypus
|
|
2
|
-
_ ___
|
|
3
|
-
/ \ / \
|
|
4
|
-
\. |: cc|
|
|
5
|
-
(.|:,---,
|
|
6
|
-
(.|: \ c|
|
|
7
|
-
(. y-'
|
|
8
|
-
\ _ /
|
|
9
|
-
m m
|
|
10
|
-
|
|
11
|
-
* home: http://rubyworks.github.com/platypus
|
|
12
|
-
* work: http://github.com/rubyworks/platypus
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
== DESCRIPTION
|
|
16
|
-
|
|
17
|
-
Platypus provides a generalized type conversion system,
|
|
18
|
-
method overloading and psuedo-classes.
|
|
19
|
-
|
|
20
|
-
== SYNOPSIS
|
|
21
|
-
|
|
22
|
-
Type conversion work like a rational duck might expect.
|
|
23
|
-
|
|
24
|
-
"1234".to(Float) => 1234.0 (Float)
|
|
25
|
-
|
|
26
|
-
Time.from("6:30") => 1234.0 (Time)
|
|
27
|
-
|
|
28
|
-
You can of course define your own.
|
|
29
|
-
|
|
30
|
-
class X
|
|
31
|
-
typecast String do |x|
|
|
32
|
-
"#{x}"
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
To overload a method, mixin the Overloadable module and use the #overload (or #sig)
|
|
37
|
-
method to define new functionality based on a specified type interface.
|
|
38
|
-
|
|
39
|
-
class X
|
|
40
|
-
include Overloadable
|
|
41
|
-
|
|
42
|
-
def f
|
|
43
|
-
"f"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
sig Integer
|
|
47
|
-
|
|
48
|
-
def f(i)
|
|
49
|
-
"f#{i}"
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
sig String, String
|
|
53
|
-
|
|
54
|
-
def f(s1, s2)
|
|
55
|
-
[s1, s2].join('+')
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
x = X.new
|
|
60
|
-
|
|
61
|
-
x.f #=> "f"
|
|
62
|
-
x.f(1) #=> "f1"
|
|
63
|
-
x.f("A","B") #=> "A+B"
|
|
64
|
-
|
|
65
|
-
Finally, the Platypus gives you the Type superclass (aka pseudo-classes).
|
|
66
|
-
|
|
67
|
-
class KiloType < Type
|
|
68
|
-
x % 1000 == 0
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
KiloType === 1000
|
|
72
|
-
KiloType === 2000
|
|
73
|
-
|
|
74
|
-
To learn more about using Platypus see the Demonstrundum[http://rubyworks.github.com/platypus/docs/qed].
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
== RELEASE NOTES
|
|
78
|
-
|
|
79
|
-
Please see HISTORY file.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
== INSTALLATION
|
|
83
|
-
|
|
84
|
-
To install with RubyGems simply open a console and type:
|
|
85
|
-
|
|
86
|
-
$ gem install platypus
|
|
87
|
-
|
|
88
|
-
Site installation can be achieved with Setup.rb (gem install setup),
|
|
89
|
-
then download the tarball package and type:
|
|
90
|
-
|
|
91
|
-
$ tar -xvzf platypus-1.0.0.tgz
|
|
92
|
-
$ cd platypus-1.0.0
|
|
93
|
-
$ setup.rb all
|
|
94
|
-
|
|
95
|
-
Windows users use 'ruby setup.rb all'.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
== COPYING
|
|
99
|
-
|
|
100
|
-
Copyright (c) 2010 Thomas Sawyer
|
|
101
|
-
|
|
102
|
-
This program is ditributed unser the terms of the *FreeBSD* license.
|
|
103
|
-
|
|
104
|
-
See COPYING.rdoc file for details.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*-* mode: rdoc *-*
|
|
108
|
-
|
data/qed/01_intro.rdoc
DELETED
data/qed/02_typecast.rdoc
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
== Type Casting
|
|
2
|
-
|
|
3
|
-
Require the casting library.
|
|
4
|
-
|
|
5
|
-
require 'platypus/typecast'
|
|
6
|
-
|
|
7
|
-
Define a couple of typecasts.
|
|
8
|
-
|
|
9
|
-
class ::String
|
|
10
|
-
typecast ::Regexp do |string|
|
|
11
|
-
/#{string}/
|
|
12
|
-
end
|
|
13
|
-
typecast ::Regexp, :multiline do |string|
|
|
14
|
-
/#{string}/m
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
::String.typecast ::Integer do |string|
|
|
19
|
-
Integer(string)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
See that they work.
|
|
23
|
-
|
|
24
|
-
::Regexp.from("ABC").assert == /ABC/
|
|
25
|
-
|
|
26
|
-
And again.
|
|
27
|
-
|
|
28
|
-
"123".to(::Integer).assert == 123
|
|
29
|
-
|
data/qed/03_type.rdoc
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
== Pseudo-Types
|
|
2
|
-
|
|
3
|
-
Require the library.
|
|
4
|
-
|
|
5
|
-
require 'platypus/type'
|
|
6
|
-
|
|
7
|
-
Now we can create types which are psuedo-classes.
|
|
8
|
-
|
|
9
|
-
class KiloType < Type
|
|
10
|
-
condition do |x|
|
|
11
|
-
x.case? Integer
|
|
12
|
-
x.kind_of?(Integer)
|
|
13
|
-
x.respond_to?(:succ)
|
|
14
|
-
x > 1000
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
KiloType.assert === 2000
|
|
19
|
-
KiloType.refute === 999
|
|
20
|
-
|
|
21
|
-
Using the convenience #x method.
|
|
22
|
-
|
|
23
|
-
class MegaType < Type
|
|
24
|
-
x.case? Integer
|
|
25
|
-
x.kind_of?(Integer)
|
|
26
|
-
x.respond_to?(:succ)
|
|
27
|
-
x > 1000000
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
MegaType.assert === 20000000
|
|
31
|
-
MegaType.refute === 999999
|
|
32
|
-
|
data/test/test_overload.rb
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
require 'platypus/overload'
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
class TC_Overload_01 < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
class X
|
|
7
|
-
include Overloadable
|
|
8
|
-
|
|
9
|
-
def x
|
|
10
|
-
"hello"
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
overload Array
|
|
14
|
-
|
|
15
|
-
def x(x)
|
|
16
|
-
[Array, x]
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
overload Symbol
|
|
20
|
-
|
|
21
|
-
def x(x)
|
|
22
|
-
[Symbol, x]
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def setup
|
|
27
|
-
@x = X.new
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def test_x
|
|
31
|
-
assert_equal( "hello", @x.x )
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def test_a
|
|
35
|
-
assert_equal( [Array, [1]], @x.x([1]) )
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_s
|
|
39
|
-
assert_equal( [Symbol, :a], @x.x(:a) )
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
#
|
|
45
|
-
class TC_Overload_02 < Test::Unit::TestCase
|
|
46
|
-
|
|
47
|
-
class X
|
|
48
|
-
include Overloadable
|
|
49
|
-
|
|
50
|
-
def x
|
|
51
|
-
"hello"
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
overload Integer
|
|
55
|
-
|
|
56
|
-
def x(i)
|
|
57
|
-
i
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
overload String, String
|
|
61
|
-
|
|
62
|
-
def x(s1, s2)
|
|
63
|
-
[s1, s2]
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def setup
|
|
69
|
-
@x = X.new
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def test_x
|
|
73
|
-
assert_equal( "hello", @x.x )
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_i
|
|
77
|
-
assert_equal( 1, @x.x(1) )
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def test_s
|
|
81
|
-
assert_equal( ["a","b"], @x.x("a","b") )
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
#
|
|
87
|
-
class TC_Overload_03 < Test::Unit::TestCase
|
|
88
|
-
|
|
89
|
-
class SubArray < Array
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
class SubSubArray < SubArray
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
class X
|
|
96
|
-
include Overloadable
|
|
97
|
-
|
|
98
|
-
def x
|
|
99
|
-
"hello"
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
overload Integer
|
|
103
|
-
|
|
104
|
-
def x(i)
|
|
105
|
-
i
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
overload Symbol
|
|
109
|
-
|
|
110
|
-
def x(s)
|
|
111
|
-
s
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
overload String, String
|
|
115
|
-
|
|
116
|
-
def x(s1, s2)
|
|
117
|
-
[s1, s2]
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
overload Symbol, String
|
|
121
|
-
|
|
122
|
-
def x(s1, s2)
|
|
123
|
-
[s1, s2]
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
overload Array
|
|
127
|
-
|
|
128
|
-
def x(a)
|
|
129
|
-
"array"
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def setup
|
|
135
|
-
@x = X.new
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
def test_x
|
|
139
|
-
assert_equal( "hello", @x.x )
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
def test_i
|
|
143
|
-
assert_equal( 1, @x.x(1) )
|
|
144
|
-
end
|
|
145
|
-
|
|
146
|
-
def test_strings
|
|
147
|
-
assert_equal( ["a","b"], @x.x("a","b") )
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def test_symbol_string
|
|
151
|
-
assert_equal( [:a,"b"], @x.x(:a,"b") )
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def test_sym
|
|
155
|
-
assert_equal( :sym, @x.x(:sym) )
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def test_subarray
|
|
159
|
-
assert_equal("array", @x.x([]))
|
|
160
|
-
assert_equal("array", @x.x(SubArray.new))
|
|
161
|
-
assert_equal("array", @x.x(SubSubArray.new))
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
#def test_raise
|
|
165
|
-
# assert_raise ArgumentError do
|
|
166
|
-
# X.module_eval do
|
|
167
|
-
# overload 42
|
|
168
|
-
# end
|
|
169
|
-
# end
|
|
170
|
-
#end
|
|
171
|
-
|
|
172
|
-
end
|
|
173
|
-
|