platypus 1.0.0 → 1.0.1
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/.ruby +44 -0
- data/HISTORY.rdoc +20 -0
- data/NOTES.rdoc +8 -0
- data/{README → README.rdoc} +38 -24
- data/lib/platypus.rb +1 -0
- data/lib/platypus/version.rb +3 -0
- data/qed/01_intro.rdoc +2 -0
- data/qed/02_typecast.rdoc +29 -0
- data/qed/03_type.rdoc +32 -0
- data/qed/04_overload.rdoc +57 -0
- metadata +62 -54
- data/HISTORY +0 -19
- data/LICENSE +0 -22
- data/PROFILE +0 -24
- data/REQUIRE +0 -6
- data/VERSION +0 -5
data/.ruby
ADDED
@@ -0,0 +1,44 @@
|
|
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
ADDED
@@ -0,0 +1,20 @@
|
|
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
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= Developer's Notes
|
2
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
|
+
|
3
11
|
== 2010-05-27 | Alias for +Overloadable#overload+
|
4
12
|
|
5
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*.
|
data/{README → README.rdoc}
RENAMED
@@ -17,46 +17,52 @@
|
|
17
17
|
Platypus provides a generalized type conversion system,
|
18
18
|
method overloading and psuedo-classes.
|
19
19
|
|
20
|
-
|
21
|
-
== RELEASE NOTES
|
22
|
-
|
23
|
-
Please see HISTORY file.
|
24
|
-
|
25
|
-
|
26
20
|
== SYNOPSIS
|
27
21
|
|
28
|
-
|
22
|
+
Type conversion work like a rational duck might expect.
|
29
23
|
|
30
24
|
"1234".to(Float) => 1234.0 (Float)
|
31
25
|
|
32
26
|
Time.from("6:30") => 1234.0 (Time)
|
33
27
|
|
34
|
-
|
28
|
+
You can of course define your own.
|
29
|
+
|
30
|
+
class X
|
31
|
+
typecast String do |x|
|
32
|
+
"#{x}"
|
33
|
+
end
|
34
|
+
end
|
35
35
|
|
36
|
-
To overload a method use the #overload
|
37
|
-
new functionality based on a specified type interface.
|
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
38
|
|
39
39
|
class X
|
40
40
|
include Overloadable
|
41
41
|
|
42
|
-
def
|
43
|
-
"
|
42
|
+
def f
|
43
|
+
"f"
|
44
44
|
end
|
45
45
|
|
46
46
|
sig Integer
|
47
47
|
|
48
|
-
def
|
49
|
-
i
|
48
|
+
def f(i)
|
49
|
+
"f#{i}"
|
50
50
|
end
|
51
51
|
|
52
52
|
sig String, String
|
53
53
|
|
54
|
-
def
|
55
|
-
[s1, s2]
|
54
|
+
def f(s1, s2)
|
55
|
+
[s1, s2].join('+')
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
|
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).
|
60
66
|
|
61
67
|
class KiloType < Type
|
62
68
|
x % 1000 == 0
|
@@ -65,19 +71,26 @@ new functionality based on a specified type interface.
|
|
65
71
|
KiloType === 1000
|
66
72
|
KiloType === 2000
|
67
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
|
+
|
68
81
|
|
69
82
|
== INSTALLATION
|
70
83
|
|
71
84
|
To install with RubyGems simply open a console and type:
|
72
85
|
|
73
|
-
$ gem install
|
86
|
+
$ gem install platypus
|
74
87
|
|
75
88
|
Site installation can be achieved with Setup.rb (gem install setup),
|
76
89
|
then download the tarball package and type:
|
77
90
|
|
78
|
-
$ tar -xvzf
|
79
|
-
$ cd
|
80
|
-
$
|
91
|
+
$ tar -xvzf platypus-1.0.0.tgz
|
92
|
+
$ cd platypus-1.0.0
|
93
|
+
$ setup.rb all
|
81
94
|
|
82
95
|
Windows users use 'ruby setup.rb all'.
|
83
96
|
|
@@ -86,9 +99,10 @@ Windows users use 'ruby setup.rb all'.
|
|
86
99
|
|
87
100
|
Copyright (c) 2010 Thomas Sawyer
|
88
101
|
|
89
|
-
This program is ditributed unser the terms of the
|
102
|
+
This program is ditributed unser the terms of the *FreeBSD* license.
|
103
|
+
|
104
|
+
See COPYING.rdoc file for details.
|
90
105
|
|
91
|
-
See LICENSE or COPYING file for details.
|
92
106
|
|
93
|
-
#--
|
94
107
|
*-* mode: rdoc *-*
|
108
|
+
|
data/lib/platypus.rb
CHANGED
data/qed/01_intro.rdoc
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/qed/03_type.rdoc
ADDED
@@ -0,0 +1,32 @@
|
|
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
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
== Overloadable
|
2
|
+
|
3
|
+
The Overloadable mixin provides a means for overloading
|
4
|
+
methods based in method signature using an elegant syntax.
|
5
|
+
To demonstrate, we first need to load the library.
|
6
|
+
|
7
|
+
require 'platypus/overload'
|
8
|
+
|
9
|
+
Now we can define a class that utilizes it.
|
10
|
+
|
11
|
+
class X
|
12
|
+
include Overloadable
|
13
|
+
|
14
|
+
sig String, String
|
15
|
+
|
16
|
+
def x(str1, str2)
|
17
|
+
str1.assert.is_a?(String)
|
18
|
+
str2.assert.is_a?(String)
|
19
|
+
end
|
20
|
+
|
21
|
+
sig Integer, Integer
|
22
|
+
|
23
|
+
def x(int1, int2)
|
24
|
+
int1.assert.is_a?(Integer)
|
25
|
+
int2.assert.is_a?(Integer)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
As you can see will placed assertions directly into our methods
|
30
|
+
definitions. We simply need to run an exmaple of each definition to
|
31
|
+
see that it worked.
|
32
|
+
|
33
|
+
x = X.new
|
34
|
+
|
35
|
+
x.x("Hello", "World")
|
36
|
+
|
37
|
+
x.x(100, 200)
|
38
|
+
|
39
|
+
But what happens if the signiture is not matched? Either an ArgumentError will
|
40
|
+
be raised.
|
41
|
+
|
42
|
+
expect ArgumentError do
|
43
|
+
x.x("Hello", 200)
|
44
|
+
end
|
45
|
+
|
46
|
+
Or it will fallback to a non-signiature definition, if one is defined.
|
47
|
+
|
48
|
+
|
49
|
+
class X
|
50
|
+
def x(obj1, obj2)
|
51
|
+
obj1.refute.is_a?(Integer)
|
52
|
+
obj2.refute.is_a?(String)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
x.x("Hello", 200)
|
57
|
+
|
metadata
CHANGED
@@ -1,78 +1,86 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: platypus
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 1
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
version: 1.0.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Thomas Sawyer
|
13
9
|
- Jonas Pfenniger
|
14
10
|
autorequire:
|
15
11
|
bindir: bin
|
16
12
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
date: 2011-10-20 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: detroit
|
17
|
+
requirement: &14563700 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *14563700
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: qed
|
28
|
+
requirement: &14562980 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *14562980
|
37
|
+
description: Provides a complete double-dispatch type conversion system, method overloadability
|
38
|
+
and psuedo-classes.
|
23
39
|
email:
|
24
40
|
executables: []
|
25
|
-
|
26
41
|
extensions: []
|
27
|
-
|
28
|
-
|
29
|
-
- README
|
30
|
-
|
42
|
+
extra_rdoc_files:
|
43
|
+
- HISTORY.rdoc
|
44
|
+
- README.rdoc
|
45
|
+
- NOTES.rdoc
|
46
|
+
files:
|
47
|
+
- .ruby
|
31
48
|
- lib/platypus/core_ext.rb
|
32
49
|
- lib/platypus/overload.rb
|
33
50
|
- lib/platypus/type.rb
|
34
51
|
- lib/platypus/typecast.rb
|
52
|
+
- lib/platypus/version.rb
|
35
53
|
- lib/platypus.rb
|
54
|
+
- qed/01_intro.rdoc
|
55
|
+
- qed/02_typecast.rdoc
|
56
|
+
- qed/03_type.rdoc
|
57
|
+
- qed/04_overload.rdoc
|
36
58
|
- test/test_overload.rb
|
37
|
-
-
|
38
|
-
-
|
39
|
-
- README
|
40
|
-
- HISTORY
|
59
|
+
- HISTORY.rdoc
|
60
|
+
- README.rdoc
|
41
61
|
- NOTES.rdoc
|
42
|
-
- REQUIRE
|
43
|
-
- VERSION
|
44
|
-
has_rdoc: true
|
45
62
|
homepage: http://rubyworks.github.com/platypus
|
46
63
|
licenses: []
|
47
|
-
|
48
64
|
post_install_message:
|
49
|
-
rdoc_options:
|
50
|
-
|
51
|
-
- Platypus API
|
52
|
-
- --main
|
53
|
-
- README
|
54
|
-
require_paths:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
55
67
|
- lib
|
56
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
- 0
|
69
|
-
version: "0"
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
70
80
|
requirements: []
|
71
|
-
|
72
|
-
|
73
|
-
rubygems_version: 1.3.6
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.10
|
74
83
|
signing_key:
|
75
84
|
specification_version: 3
|
76
|
-
summary:
|
77
|
-
test_files:
|
78
|
-
- test/test_overload.rb
|
85
|
+
summary: Riding on Types with Ruby
|
86
|
+
test_files: []
|
data/HISTORY
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
= Change History
|
2
|
-
|
3
|
-
# == History
|
4
|
-
#
|
5
|
-
# * 2006-06-06 3v1l_d4y:
|
6
|
-
# * Removed transformation options.
|
7
|
-
# * Removed StringIO typecast. It is not required by default.
|
8
|
-
# * Added TypeCastException for better error reporting while coding.
|
9
|
-
#
|
10
|
-
|
11
|
-
== 1.0.0 // 2009-07-07
|
12
|
-
|
13
|
-
This is the initial stand-alone release of TypeCast,
|
14
|
-
spun-off from Ruby Facets.
|
15
|
-
|
16
|
-
* 1 Major Enhancement
|
17
|
-
|
18
|
-
* Happy Birthday!
|
19
|
-
|
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
The MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2010 Thomas Sawyer
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
22
|
-
|
data/PROFILE
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title : Platypus
|
3
|
-
suite : rubyworks
|
4
|
-
summary: Type Casting System
|
5
|
-
license: MIT
|
6
|
-
created: 2004-01-01
|
7
|
-
|
8
|
-
copyright:
|
9
|
-
Copyright (c) 2004 Thomas Sawyer
|
10
|
-
|
11
|
-
authors:
|
12
|
-
- Thomas Sawyer
|
13
|
-
- Jonas Pfenniger
|
14
|
-
|
15
|
-
description:
|
16
|
-
Provides a complete double-dispatch type conversion system,
|
17
|
-
method overloadability and psuedo-classes.
|
18
|
-
|
19
|
-
resources:
|
20
|
-
homepage: http://rubyworks.github.com/platypus
|
21
|
-
development: http://github.com/rubyworks/platypus
|
22
|
-
repository: http://rubyworks.github.com/platypus.git
|
23
|
-
forum: http://googlegroups/group/rubyworks-mailinglist
|
24
|
-
|
data/REQUIRE
DELETED