stitcher 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,107 @@
1
+ module Stitcher
2
+ module TypeOperators
3
+ def | other
4
+ Stitcher.type_or self, other
5
+ end
6
+
7
+ def & other
8
+ Stitcher.type_and self, other
9
+ end
10
+
11
+ def !
12
+ Stitcher.type_not self
13
+ end
14
+
15
+ def +@
16
+ Stitcher.type_plus_at self
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+ module Stitcher module Refinements
23
+ module Type
24
+ refine Object do
25
+ def type
26
+ stitcher_type
27
+ end
28
+
29
+ def stitcher_type
30
+ Stitcher::Type.new self.class == Class ? self : self.class
31
+ end
32
+
33
+ def classtype
34
+ self.class == Class ? self : self.class
35
+ end
36
+ end
37
+
38
+ refine Class do
39
+ include TypeOperators
40
+ end
41
+ end
42
+ end end
43
+
44
+
45
+ using Stitcher::Refinements::Type
46
+
47
+
48
+ module Stitcher
49
+ class Type
50
+ include TypeOperators
51
+
52
+ def initialize klass = nil, &block
53
+ @comp = block
54
+ @comp = lambda do |other, op|
55
+ # change operator "<" to ">".
56
+ return other.comp(klass, op.to_s.tr("<>", "><")) if other.class == Type
57
+ return self.comp(other, :==) if op.to_sym == :===
58
+ klass.__send__ op, other.classtype
59
+ end unless block_given?
60
+ end
61
+
62
+ def comp other, op
63
+ !!@comp.(other, op)
64
+ end
65
+
66
+ [:==, :!=, :>=, :<=, :>, :<, :===].each do |op|
67
+ define_method(op) do |other|
68
+ comp other, op
69
+ end
70
+ end
71
+
72
+ def type
73
+ self
74
+ end
75
+ end
76
+
77
+ def type_or a, b
78
+ Type.new do |other, op|
79
+ (a.type.__send__ op, other.type) || (b.type.__send__ op, other.type)
80
+ end
81
+ end
82
+ module_function :type_or
83
+
84
+
85
+ def type_and a, b
86
+ Type.new do |other, op|
87
+ (a.type.__send__ op, other.type) && (b.type.__send__ op, other.type)
88
+ end
89
+ end
90
+ module_function :type_and
91
+
92
+ def type_not a
93
+ Type.new do |other, op|
94
+ !(a.type.__send__ op, other.type)
95
+ end
96
+ end
97
+ module_function :type_not
98
+
99
+ def type_plus_at a
100
+ Type.new do |other, op|
101
+ next a.type >= other if op.to_sym == :===
102
+ a.type.__send__ op, other.type
103
+ end
104
+ end
105
+ module_function :type_plus_at
106
+ end
107
+
@@ -0,0 +1,11 @@
1
+ require_relative "../type"
2
+
3
+ class Object
4
+ def type
5
+ stitcher_type
6
+ end
7
+
8
+ def stitcher_type
9
+ Stitcher::Type.new self.class == Class ? self : self.class
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require_relative "./core_ext"
2
+
3
+ using StitcherArrayEx
4
+
5
+ module Stitcher module VariadicArgument
6
+ def +@
7
+ lambda { |other|
8
+ return false if size > other.size
9
+ clone.fill(last, size, other.size - size) === other
10
+ }
11
+ end
12
+ end end
@@ -0,0 +1,3 @@
1
+ module Stitcher
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stitcher/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stitcher"
8
+ spec.version = Stitcher::VERSION
9
+ spec.authors = ["manga_osyo"]
10
+ spec.email = ["manga.osyo@gmail.com"]
11
+
12
+ spec.summary = %q{Typed Programing}
13
+ spec.description = %q{Typed Programing}
14
+ spec.homepage = "https://github.com/osyo-manga/gem-stitcher"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stitcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - manga_osyo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Typed Programing
56
+ email:
57
+ - manga.osyo@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - docs/matome.md
71
+ - docs/stitcher.md
72
+ - docs/type.md
73
+ - docs/typed.md
74
+ - example/core_ex.rb
75
+ - example/register.rb
76
+ - example/simple.rb
77
+ - example/type.rb
78
+ - lib/stitcher.rb
79
+ - lib/stitcher/accessor.rb
80
+ - lib/stitcher/concepts.rb
81
+ - lib/stitcher/core.rb
82
+ - lib/stitcher/core_ext.rb
83
+ - lib/stitcher/define_method.rb
84
+ - lib/stitcher/operators.rb
85
+ - lib/stitcher/register.rb
86
+ - lib/stitcher/require.rb
87
+ - lib/stitcher/stitch.rb
88
+ - lib/stitcher/type.rb
89
+ - lib/stitcher/type/core_ext.rb
90
+ - lib/stitcher/variadic_argument.rb
91
+ - lib/stitcher/version.rb
92
+ - stitcher.gemspec
93
+ homepage: https://github.com/osyo-manga/gem-stitcher
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Typed Programing
117
+ test_files: []