laurel 0.l.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7454f43d9415c5cc4bc81888ed944205ac9daf44
4
+ data.tar.gz: fdf4a09a9710518396f2503ba40681ea8da81ea5
5
+ SHA512:
6
+ metadata.gz: 746b13bd57baecc7f573318c1e25f0aa0b9f8e32c0166f9fcf15e2c5bb4ededf727e0f2fead887822ddb00435971837e3b3d9458690b1fd90f0625df3331c7c0
7
+ data.tar.gz: b10ff7fa9867816ebb3b6d71e583129af335c80042ed31670e0980db2979eca282f399cb0e448070071b3517f78990cafa0ecb5b95946e0e22b0a5369d16779a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in laurel.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Laurel
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'laurel'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install laurel
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require "laurel"
23
+
24
+ using Laurel::Refine
25
+
26
+ (x & y).any_method # => x.any_method && y.any_method
27
+ ```
28
+
29
+ ## Release Note
30
+
31
+ #### 0.1.1
32
+
33
+ * Bug fix `Laurel::Refine.usable`
34
+
35
+ #### 0.1.0
36
+
37
+ * First release
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/osyo-manga/gem-laurel.
48
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "laurel"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ require "laurel"
2
+
3
+ using Laurel::Refine
4
+
5
+ Boolean = FalseClass | TrueClass
6
+
7
+ p Boolean === true
8
+ # => true
9
+
10
+ p Boolean === false
11
+ # => true
12
+
13
+ p Boolean === 0
14
+ # => false
15
+
16
+ p Boolean === nil
17
+ # => false
data/example/case.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "laurel"
2
+
3
+ using Laurel::Refine
4
+
5
+ def func n
6
+ case n
7
+ when Integer & 0.method(:>).to_proc
8
+ "minus"
9
+ when Integer & 0.method(:==).to_proc
10
+ "zero"
11
+ when Integer & 0.method(:<).to_proc
12
+ "plus"
13
+ else
14
+ "other"
15
+ end
16
+ end
17
+
18
+ p func -1
19
+ # => "minus"
20
+
21
+ p func 0
22
+ # => "zero"
23
+
24
+ p func 1
25
+ # => "plus"
26
+
27
+ p func "homu"
28
+ # => "other"
29
+
30
+ p func []
31
+ # => "other"
data/example/simple.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "laurel"
2
+
3
+ p Laurel.and(1, 2).to_s # => 1.to_s && 2.to_s
4
+
5
+ homu_or_mami = Laurel.or("homu", "mado")
6
+
7
+ p homu_or_mami == "homu"
8
+ # => true
9
+
10
+ p homu_or_mami == "mado"
11
+ # => true
12
+
13
+ p homu_or_mami == "mami"
14
+ # => false
15
+
16
+
17
+ # Using operators
18
+ # define Object#& Object#| Object#!
19
+ using Laurel::Refine
20
+
21
+ p "homu" | "mado" == "homu"
22
+ # => true
23
+
24
+ p "homu" | "mado" == "mado"
25
+ # => true
26
+
27
+ p "homu" | "mado" == "mami"
28
+ # => false
29
+
data/laurel.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'laurel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "laurel"
8
+ spec.version = Laurel::VERSION
9
+ spec.authors = ["manga_osyo"]
10
+ spec.email = ["manga.osyo@gmail.com"]
11
+
12
+ spec.summary = %q{}
13
+ spec.description = %q{}
14
+ spec.homepage = ""
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 12.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "./operator.rb"
2
+
3
+ module Laurel module Refine
4
+ def self.const_missing name
5
+ klass = ::ObjectSpace.each_object(::Class).find { |klass| klass.name == name.to_s }
6
+ usable klass
7
+ end
8
+
9
+ def self.usable klass
10
+ ::Module.new do
11
+ refine klass do
12
+ include ::Laurel::Operator
13
+ end
14
+ end
15
+ end
16
+
17
+ include Refine::Object
18
+ include usable Laurel::Proxy
19
+ end end
@@ -0,0 +1,15 @@
1
+ require_relative "./proxy.rb"
2
+
3
+ module Laurel module Operator
4
+ def & other
5
+ Laurel.and(self, other)
6
+ end
7
+
8
+ def | other
9
+ Laurel.or(self, other)
10
+ end
11
+
12
+ def !
13
+ Laurel.not(self)
14
+ end
15
+ end end
@@ -0,0 +1,30 @@
1
+ module Laurel
2
+ class Proxy < BasicObject
3
+ def initialize &block
4
+ @block = block
5
+ end
6
+
7
+ def method_missing name, *args, &block
8
+ @block.call name, *args, &block
9
+ end
10
+ end
11
+
12
+ module_function
13
+ def proxy ignores = [], &block
14
+ Class.new(Laurel::Proxy) {
15
+ def initialize &block
16
+ super &block
17
+ end
18
+ ignores.each { |name|
19
+ define_method(name){ |*args, &block|
20
+ method_missing name, *args, &block
21
+ }
22
+ }
23
+ }.new(&block)
24
+ end
25
+
26
+ module_function
27
+ def proxy_all &block
28
+ Laurel.proxy BasicObject.instance_methods, &block
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Laurel
2
+ VERSION = "0.l.1"
3
+ end
data/lib/laurel.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "laurel/version"
2
+ require "laurel/proxy"
3
+ require "laurel/operator"
4
+ require "laurel/core_refine"
5
+
6
+ module Laurel
7
+ module_function
8
+ def and a, b
9
+ Laurel.proxy([:==, :!=, :!]) { |name, *args, &block|
10
+ a.__send__(name, *args, &block) \
11
+ && b.__send__(name, *args, &block)
12
+ }
13
+ end
14
+
15
+ module_function
16
+ def or a, b
17
+ Laurel.proxy([:==, :!=, :!]) { |name, *args, &block|
18
+ a.__send__(name, *args, &block) \
19
+ || b.__send__(name, *args, &block)
20
+ }
21
+ end
22
+
23
+ module_function
24
+ def not a
25
+ Laurel.proxy([:==, :!=, :!]) { |name, *args, &block|
26
+ !a.__send__(name, *args, &block)
27
+ }
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: laurel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.l.1
5
+ platform: ruby
6
+ authors:
7
+ - manga_osyo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-13 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: ''
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
+ - example/boolean.rb
71
+ - example/case.rb
72
+ - example/simple.rb
73
+ - laurel.gemspec
74
+ - lib/laurel.rb
75
+ - lib/laurel/core_refine.rb
76
+ - lib/laurel/operator.rb
77
+ - lib/laurel/proxy.rb
78
+ - lib/laurel/version.rb
79
+ homepage: ''
80
+ licenses: []
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.3.1
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.13
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: ''
102
+ test_files: []