types 0.1.3 → 0.3.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
- checksums.yaml.gz.sig +0 -0
- data/agent.md +47 -0
- data/context/usage.md +195 -0
- data/lib/types/any.rb +74 -0
- data/lib/types/array.rb +77 -0
- data/lib/types/block.rb +61 -0
- data/lib/types/boolean.rb +38 -0
- data/lib/types/class.rb +77 -0
- data/lib/types/decimal.rb +32 -0
- data/lib/types/float.rb +31 -0
- data/lib/types/generic.rb +38 -0
- data/lib/types/hash.rb +73 -0
- data/lib/types/integer.rb +31 -0
- data/lib/types/interface.rb +100 -0
- data/lib/types/lambda.rb +67 -0
- data/lib/types/method.rb +90 -0
- data/lib/types/nil.rb +35 -0
- data/lib/types/numeric.rb +30 -0
- data/lib/types/string.rb +30 -0
- data/lib/types/symbol.rb +30 -0
- data/lib/types/tuple.rb +74 -0
- data/lib/types/version.rb +8 -0
- data/lib/types.rb +46 -129
- data/license.md +21 -0
- data/readme.md +71 -0
- data.tar.gz.sig +0 -0
- metadata +79 -98
- metadata.gz.sig +0 -0
- data/.document +0 -5
- data/Gemfile +0 -12
- data/Gemfile.lock +0 -20
- data/LICENSE.txt +0 -20
- data/README.md +0 -52
- data/Rakefile +0 -37
- data/VERSION +0 -1
- data/types.gemspec +0 -56
data/lib/types.rb
CHANGED
@@ -1,131 +1,48 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2022-2025, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative "types/version"
|
7
|
+
|
8
|
+
require_relative "types/any"
|
9
|
+
require_relative "types/array"
|
10
|
+
require_relative "types/block"
|
11
|
+
require_relative "types/boolean"
|
12
|
+
require_relative "types/class"
|
13
|
+
require_relative "types/decimal"
|
14
|
+
require_relative "types/float"
|
15
|
+
require_relative "types/hash"
|
16
|
+
require_relative "types/integer"
|
17
|
+
require_relative "types/interface"
|
18
|
+
require_relative "types/lambda"
|
19
|
+
require_relative "types/method"
|
20
|
+
require_relative "types/nil"
|
21
|
+
require_relative "types/numeric"
|
22
|
+
require_relative "types/string"
|
23
|
+
require_relative "types/symbol"
|
24
|
+
require_relative "types/tuple"
|
25
|
+
|
26
|
+
# @namespace
|
11
27
|
module Types
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# Returns types which are part of this type.
|
33
|
-
# @return [Array] array of types objects
|
34
|
-
#
|
35
|
-
|
36
|
-
def type_types
|
37
|
-
[ ]
|
38
|
-
end
|
39
|
-
|
40
|
-
##
|
41
|
-
# Matches object is of this type.
|
42
|
-
#
|
43
|
-
# @param [Object] object object for type matching
|
44
|
-
# @return [Boolean] +true+ if match, +false+ in otherwise
|
45
|
-
#
|
46
|
-
|
47
|
-
def match_type?(object)
|
48
|
-
result = object.kind_of_any? self.type_classes
|
49
|
-
if not result
|
50
|
-
result = object.type_of_any? self.type_types
|
51
|
-
end
|
52
|
-
|
53
|
-
return result
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# Defines generic boolean type.
|
60
|
-
# @abstract
|
61
|
-
#
|
62
|
-
|
63
|
-
class Boolean < Type
|
64
|
-
|
65
|
-
##
|
66
|
-
# Returns classes which are part of this type.
|
67
|
-
# In case of boolean +TrueClass+ and +FalseClass+.
|
68
|
-
#
|
69
|
-
# @return [Array] array of types objects
|
70
|
-
#
|
71
|
-
|
72
|
-
def type_classes
|
73
|
-
[TrueClass, FalseClass]
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
# Extension of built-in Object class.
|
81
|
-
#
|
82
|
-
|
83
|
-
class Object
|
84
|
-
|
85
|
-
##
|
86
|
-
# Indicates object is type of some class.
|
87
|
-
# If class isn't {Types::Type Type}, matches against +#kind_of?+.
|
88
|
-
#
|
89
|
-
# @param [Types::Type, Class] cls some type or class specification
|
90
|
-
# @return [Boolean] +true+ if it is, +false+ in otherwise
|
91
|
-
#
|
92
|
-
|
93
|
-
def type_of?(cls)
|
94
|
-
cls_new = cls::new
|
95
|
-
if cls_new.kind_of? Types::Type
|
96
|
-
cls_new.match_type? self
|
97
|
-
else
|
98
|
-
self.kind_of? cls
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
##
|
103
|
-
# Indicates object is type of some class in the list.
|
104
|
-
# If class isn't {Types::Type Type}, matches against +#kind_of?+.
|
105
|
-
#
|
106
|
-
# @param [Array] classes array of {Types::Type Type} or +Class+ objects
|
107
|
-
# @return [Boolean] +true+ if it is, +false+ in otherwise
|
108
|
-
#
|
109
|
-
|
110
|
-
def type_of_any?(classes)
|
111
|
-
if not classes.kind_of? Array
|
112
|
-
raise Exception::new("Array expected.")
|
113
|
-
end
|
114
|
-
|
115
|
-
classes.each do |cls|
|
116
|
-
if self.type_of? cls
|
117
|
-
return true
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
return false
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
##
|
126
|
-
# Redefines generic boolean type in main namespace.
|
127
|
-
# @abstract
|
128
|
-
#
|
129
|
-
|
130
|
-
class Boolean < Types::Boolean
|
28
|
+
# The main module for the types library.
|
29
|
+
#
|
30
|
+
# Provides parsing and construction of type signatures.
|
31
|
+
#
|
32
|
+
# ```ruby
|
33
|
+
# Types.parse("Array(String)") # => Types::Array(Types::String)
|
34
|
+
# ```
|
35
|
+
VALID_SIGNATURE = /\A[a-zA-Z\(\):,_|\s]+\z/
|
36
|
+
|
37
|
+
# Parses a type signature string and returns the corresponding type instance.
|
38
|
+
# @parameter signature [String] The type signature to parse.
|
39
|
+
# @returns [Object] The type instance.
|
40
|
+
# @raises [ArgumentError] if the signature is invalid.
|
41
|
+
def self.parse(signature)
|
42
|
+
if signature =~ VALID_SIGNATURE
|
43
|
+
eval(signature, binding)
|
44
|
+
else
|
45
|
+
raise ArgumentError, "Invalid type signature: #{signature.inspect}!"
|
46
|
+
end
|
47
|
+
end
|
131
48
|
end
|
data/license.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# MIT License
|
2
|
+
|
3
|
+
Copyright, 2022-2025, by Samuel Williams.
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/readme.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Types
|
2
|
+
|
3
|
+
Provides abstract types for the Ruby programming language which can used for documentation and evaluation purposes.
|
4
|
+
|
5
|
+
[](https://github.com/ioquatix/types/actions?workflow=Test)
|
6
|
+
|
7
|
+
## Motivation
|
8
|
+
|
9
|
+
I've been working on documentation tools and Ruby has several implementations for adding type information. However, I've feel like we've over-complicated the language of types and I'd like something simpler and more compatible with the Ruby language.
|
10
|
+
|
11
|
+
The original design started in [bake](https://github.com/ioquatix/bake) which uses `@parameter name [Signature] description` comments to document the types of parameters. The command-line interface of bake uses the type signature to coerce string arguments to the desired type. This has been a useful strategy to reduce code duplication and to make the code more readable.
|
12
|
+
|
13
|
+
Subsequently, I started using these type signatures in [decode](https://github.com/ioquatix/decode) which uses similar `@parameter` comments. This information is fed into [utopia-project](https://github.com/socketry/utopia-project) which can present this information as part of the generated documentation.
|
14
|
+
|
15
|
+
The expressions possible with this gem are a subset of all possible expressions in Ruby's type system. This is by design. At some point in the future, it is likely we will automate conversion of type signatures to the RBS compatible type signature files. This will allow us to use the same type signatures in the documentation and in the code.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
``` shell
|
20
|
+
bundle add types
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Parsing type signatures can be done using {ruby Types.parse} which returns a object that represents the given type, e.g.
|
26
|
+
|
27
|
+
``` ruby
|
28
|
+
string_type = Types.parse("String")
|
29
|
+
string_type # => Types::String
|
30
|
+
|
31
|
+
array_type = Types.parse("Array(String)")
|
32
|
+
array_type.class # => Types::Array
|
33
|
+
|
34
|
+
hash_type = Types.parse("Hash(String, Integer)")
|
35
|
+
hash_type.key_type # => Types::String
|
36
|
+
hash_type.value_type # => Types::Integer
|
37
|
+
```
|
38
|
+
|
39
|
+
You can generate a string representation of a type too:
|
40
|
+
|
41
|
+
``` ruby
|
42
|
+
# A lambda that takes an Integer as an argument and returns an Integer:
|
43
|
+
lambda_type = Types.parse("Lambda(Integer, returns: Integer)")
|
44
|
+
lambda_type.to_s # => "Lambda(Integer, returns: Integer)"
|
45
|
+
```
|
46
|
+
|
47
|
+
### String Parsing
|
48
|
+
|
49
|
+
In addition, you can coerce strings into strongly typed values:
|
50
|
+
|
51
|
+
``` ruby
|
52
|
+
array_type = Types.parse("Array(String)")
|
53
|
+
array_type.parse("'foo', 'bar'") # => ["foo", "bar"]
|
54
|
+
```
|
55
|
+
|
56
|
+
This can be useful for argument parsing.
|
57
|
+
|
58
|
+
### Documentation
|
59
|
+
|
60
|
+
This gem is designed to be integrated into documentation tools. It provides a way to document the types of parameters and return values of a function. This information is stored in `@parameter` and `@returns` comments.
|
61
|
+
|
62
|
+
``` ruby
|
63
|
+
# Double the value of a number.
|
64
|
+
# @parameter value [Numeric] The value to double.
|
65
|
+
# @returns [Numeric] The doubled value.
|
66
|
+
def double(value)
|
67
|
+
return value * 2
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
The motivation for discrete parameter and return types is to make integration with documentation tools easier. Specifically, language servers can use this information to provide context sensitive type information and documentation which is hard to do with existing formats like `rdoc`.
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
CHANGED
@@ -1,111 +1,92 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: types
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.1.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
6
5
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
9
|
-
autorequire:
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
10
8
|
bindir: bin
|
11
|
-
cert_chain:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.0.0
|
46
|
-
type: :development
|
47
|
-
prerelease: false
|
48
|
-
version_requirements: *id003
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: jeweler
|
51
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
|
-
requirements:
|
54
|
-
- - ~>
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 1.5.2
|
57
|
-
type: :development
|
58
|
-
prerelease: false
|
59
|
-
version_requirements: *id004
|
60
|
-
description:
|
61
|
-
email: martinkozak@martinkozak.net
|
9
|
+
cert_chain:
|
10
|
+
- |
|
11
|
+
-----BEGIN CERTIFICATE-----
|
12
|
+
MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
|
13
|
+
ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
|
14
|
+
CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
|
15
|
+
MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
|
16
|
+
MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
|
17
|
+
bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
|
18
|
+
igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
|
19
|
+
9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
|
20
|
+
sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
|
21
|
+
e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
|
22
|
+
XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
|
23
|
+
RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
|
24
|
+
tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
|
25
|
+
zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
|
26
|
+
xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
|
27
|
+
BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
|
28
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
|
29
|
+
aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
|
30
|
+
cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
|
31
|
+
xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
|
32
|
+
c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
|
33
|
+
8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
|
34
|
+
JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
|
35
|
+
eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
|
36
|
+
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
37
|
+
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
38
|
+
-----END CERTIFICATE-----
|
39
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
40
|
+
dependencies: []
|
62
41
|
executables: []
|
63
|
-
|
64
42
|
extensions: []
|
65
|
-
|
66
|
-
|
67
|
-
-
|
68
|
-
-
|
69
|
-
files:
|
70
|
-
- .document
|
71
|
-
- Gemfile
|
72
|
-
- Gemfile.lock
|
73
|
-
- LICENSE.txt
|
74
|
-
- README.md
|
75
|
-
- Rakefile
|
76
|
-
- VERSION
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- agent.md
|
46
|
+
- context/usage.md
|
77
47
|
- lib/types.rb
|
78
|
-
- types.
|
79
|
-
|
80
|
-
|
81
|
-
|
48
|
+
- lib/types/any.rb
|
49
|
+
- lib/types/array.rb
|
50
|
+
- lib/types/block.rb
|
51
|
+
- lib/types/boolean.rb
|
52
|
+
- lib/types/class.rb
|
53
|
+
- lib/types/decimal.rb
|
54
|
+
- lib/types/float.rb
|
55
|
+
- lib/types/generic.rb
|
56
|
+
- lib/types/hash.rb
|
57
|
+
- lib/types/integer.rb
|
58
|
+
- lib/types/interface.rb
|
59
|
+
- lib/types/lambda.rb
|
60
|
+
- lib/types/method.rb
|
61
|
+
- lib/types/nil.rb
|
62
|
+
- lib/types/numeric.rb
|
63
|
+
- lib/types/string.rb
|
64
|
+
- lib/types/symbol.rb
|
65
|
+
- lib/types/tuple.rb
|
66
|
+
- lib/types/version.rb
|
67
|
+
- license.md
|
68
|
+
- readme.md
|
69
|
+
homepage: https://github.com/ioquatix/types
|
70
|
+
licenses:
|
82
71
|
- MIT
|
83
|
-
|
72
|
+
metadata:
|
73
|
+
funding_uri: https://github.com/sponsors/ioquatix/
|
74
|
+
source_code_uri: https://github.com/ioquatix/types.git
|
84
75
|
rdoc_options: []
|
85
|
-
|
86
|
-
require_paths:
|
76
|
+
require_paths:
|
87
77
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
|
90
|
-
requirements:
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
91
80
|
- - ">="
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
version: "0"
|
97
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
|
-
requirements:
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
100
85
|
- - ">="
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version:
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
103
88
|
requirements: []
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
signing_key:
|
108
|
-
specification_version: 3
|
109
|
-
summary: Introduces group of classes as eqivalent to some data types in other languages such as boolean and allows introspection according to type of class too. In fact, partially replaces multiple inheritance because introduces unlimited formal genericity for every class.
|
89
|
+
rubygems_version: 3.6.7
|
90
|
+
specification_version: 4
|
91
|
+
summary: A simple human-readable and Ruby-parsable type library.
|
110
92
|
test_files: []
|
111
|
-
|
metadata.gz.sig
ADDED
Binary file
|
data/.document
DELETED
data/Gemfile
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
gem "multitype-introspection", ">= 0.1.0"
|
5
|
-
gem "abstract", ">= 1.0.0"
|
6
|
-
|
7
|
-
# Add dependencies to develop your gem here.
|
8
|
-
# Include everything needed to run rake, tests, features, etc.
|
9
|
-
group :development do
|
10
|
-
gem "bundler", "~> 1.0.0"
|
11
|
-
gem "jeweler", "~> 1.5.2"
|
12
|
-
end
|
data/Gemfile.lock
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
abstract (1.0.0)
|
5
|
-
git (1.2.5)
|
6
|
-
jeweler (1.5.2)
|
7
|
-
bundler (~> 1.0.0)
|
8
|
-
git (>= 1.2.5)
|
9
|
-
rake
|
10
|
-
multitype-introspection (0.1.0)
|
11
|
-
rake (0.8.7)
|
12
|
-
|
13
|
-
PLATFORMS
|
14
|
-
ruby
|
15
|
-
|
16
|
-
DEPENDENCIES
|
17
|
-
abstract (>= 1.0.0)
|
18
|
-
bundler (~> 1.0.0)
|
19
|
-
jeweler (~> 1.5.2)
|
20
|
-
multitype-introspection (>= 0.1.0)
|
data/LICENSE.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2011 Martin Kozák
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
Ruby Types
|
2
|
-
==========
|
3
|
-
|
4
|
-
**Ruby Types** introduces *group of classes* as eqivalent to some data
|
5
|
-
types in other languages such as `boolean` and allows introspection
|
6
|
-
according to type of class too. In fact, partially replaces multiple
|
7
|
-
inheritance because introduces unlimited formal genericity for every
|
8
|
-
class.
|
9
|
-
|
10
|
-
For example define:
|
11
|
-
|
12
|
-
class Boolean < Type
|
13
|
-
def type_classes
|
14
|
-
[TrueClass, FalseClass]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
Then you can call:
|
19
|
-
|
20
|
-
foo = 5
|
21
|
-
bar = true
|
22
|
-
|
23
|
-
foo.type_of? Boolean # returns false
|
24
|
-
bar.type_of? Boolean # returns true
|
25
|
-
|
26
|
-
Binding back to classic behaviour works:
|
27
|
-
|
28
|
-
foo.type_of? Numeric # returns true
|
29
|
-
|
30
|
-
By overriding `#type_types` method of the `Type` class you can achieve
|
31
|
-
also types inheritance by the same way as mentioned above.
|
32
|
-
|
33
|
-
|
34
|
-
Contributing
|
35
|
-
------------
|
36
|
-
|
37
|
-
1. Fork it.
|
38
|
-
2. Create a branch (`git checkout -b 20101220-my-change`).
|
39
|
-
3. Commit your changes (`git commit -am "Added something"`).
|
40
|
-
4. Push to the branch (`git push origin 20101220-my-change`).
|
41
|
-
5. Create an [Issue][1] with a link to your branch.
|
42
|
-
6. Enjoy a refreshing Diet Coke and wait.
|
43
|
-
|
44
|
-
|
45
|
-
Copyright
|
46
|
-
---------
|
47
|
-
|
48
|
-
Copyright © 2011 [Martin Kozák][2]. See `LICENSE.txt` for
|
49
|
-
further details.
|
50
|
-
|
51
|
-
[1]: http://github.com/martinkozak/types/issues
|
52
|
-
[2]: http://www.martinkozak.net/
|
data/Rakefile
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler'
|
4
|
-
begin
|
5
|
-
Bundler.setup(:default, :development)
|
6
|
-
rescue Bundler::BundlerError => e
|
7
|
-
$stderr.puts e.message
|
8
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
-
exit e.status_code
|
10
|
-
end
|
11
|
-
require 'rake'
|
12
|
-
|
13
|
-
require 'jeweler'
|
14
|
-
Jeweler::Tasks.new do |gem|
|
15
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
-
gem.name = "types"
|
17
|
-
gem.homepage = "http://github.com/martinkozak/types"
|
18
|
-
gem.license = "MIT"
|
19
|
-
gem.summary = 'Introduces group of classes as eqivalent to some data types in other languages such as boolean and allows introspection according to type of class too. In fact, partially replaces multiple inheritance because introduces unlimited formal genericity for every class.'
|
20
|
-
gem.email = "martinkozak@martinkozak.net"
|
21
|
-
gem.authors = ["Martin Kozák"]
|
22
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
-
end
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
require 'rake/rdoctask'
|
30
|
-
Rake::RDocTask.new do |rdoc|
|
31
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
-
|
33
|
-
rdoc.rdoc_dir = 'rdoc'
|
34
|
-
rdoc.title = "types #{version}"
|
35
|
-
rdoc.rdoc_files.include('README*')
|
36
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.3
|
data/types.gemspec
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{types}
|
8
|
-
s.version = "0.1.3"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Martin Kozák"]
|
12
|
-
s.date = %q{2011-03-01}
|
13
|
-
s.email = %q{martinkozak@martinkozak.net}
|
14
|
-
s.extra_rdoc_files = [
|
15
|
-
"LICENSE.txt",
|
16
|
-
"README.md"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".document",
|
20
|
-
"Gemfile",
|
21
|
-
"Gemfile.lock",
|
22
|
-
"LICENSE.txt",
|
23
|
-
"README.md",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"lib/types.rb",
|
27
|
-
"types.gemspec"
|
28
|
-
]
|
29
|
-
s.homepage = %q{http://github.com/martinkozak/types}
|
30
|
-
s.licenses = ["MIT"]
|
31
|
-
s.require_paths = ["lib"]
|
32
|
-
s.rubygems_version = %q{1.5.3}
|
33
|
-
s.summary = %q{Introduces group of classes as eqivalent to some data types in other languages such as boolean and allows introspection according to type of class too. In fact, partially replaces multiple inheritance because introduces unlimited formal genericity for every class.}
|
34
|
-
|
35
|
-
if s.respond_to? :specification_version then
|
36
|
-
s.specification_version = 3
|
37
|
-
|
38
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
39
|
-
s.add_runtime_dependency(%q<multitype-introspection>, [">= 0.1.0"])
|
40
|
-
s.add_runtime_dependency(%q<abstract>, [">= 1.0.0"])
|
41
|
-
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
42
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
43
|
-
else
|
44
|
-
s.add_dependency(%q<multitype-introspection>, [">= 0.1.0"])
|
45
|
-
s.add_dependency(%q<abstract>, [">= 1.0.0"])
|
46
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
48
|
-
end
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<multitype-introspection>, [">= 0.1.0"])
|
51
|
-
s.add_dependency(%q<abstract>, [">= 1.0.0"])
|
52
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
53
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|