maybe_monad 0.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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +9 -0
- data/lib/maybe_monad.rb +35 -0
- data/lib/maybe_monad/version.rb +3 -0
- data/maybe_monad.gemspec +23 -0
- data/maybe_monad.png +0 -0
- data/spec/spec_maybe_monad.rb +49 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 =
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# MaybeMonad
|
2
|
+
|
3
|
+
Another maybe monad library for ruby.
|
4
|
+
|
5
|
+
![maybe_monad][]
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'maybe_monad'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install maybe_monad
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
32
|
+
|
33
|
+
[maybe_monad]: maybe_monad.png
|
data/Rakefile
ADDED
data/lib/maybe_monad.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "maybe_monad/version"
|
2
|
+
|
3
|
+
class Object
|
4
|
+
def maybe
|
5
|
+
MaybeMonad::Monad.new(self)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module MaybeMonad
|
10
|
+
|
11
|
+
class Monad
|
12
|
+
|
13
|
+
instance_methods.each do |v|
|
14
|
+
undef_method(v) unless %w(object_id __id__ __send__).include?(v.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(just)
|
18
|
+
@just = just
|
19
|
+
end
|
20
|
+
|
21
|
+
def just
|
22
|
+
@just
|
23
|
+
end
|
24
|
+
|
25
|
+
def method_missing(name, *args)
|
26
|
+
# default, nil don't respond to any method
|
27
|
+
@just.nil? ? Monad.new(nil) : Monad.new(@just.__send__(name, *args))
|
28
|
+
|
29
|
+
## extra, nil respond to methods that can respond
|
30
|
+
#@just.respond_to?(name) ? Monad.new(@just.__send__(name, *args)) : Monad.new(nil)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/maybe_monad.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'maybe_monad/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "maybe_monad"
|
8
|
+
spec.version = MaybeMonad::VERSION
|
9
|
+
spec.authors = ["liangjingyang"]
|
10
|
+
spec.email = ["simple.continue@gmail.com"]
|
11
|
+
spec.description = %q{another maybe monad library}
|
12
|
+
spec.summary = %q{another maybe monad library}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/maybe_monad.png
ADDED
Binary file
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'maybe_monad'
|
3
|
+
|
4
|
+
describe MaybeMonad::Monad do
|
5
|
+
|
6
|
+
before do
|
7
|
+
end
|
8
|
+
|
9
|
+
# default, nil don't respond to any method
|
10
|
+
describe "test soup is nil" do
|
11
|
+
it "must return nil" do
|
12
|
+
nil.maybe.to_s.just.must_equal nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
## extra, nil respond to methods that can respond
|
17
|
+
#describe "test soup is nil" do
|
18
|
+
#it 'must return ""' do
|
19
|
+
#nil.maybe.to_s.just.must_equal ""
|
20
|
+
#end
|
21
|
+
#end
|
22
|
+
|
23
|
+
## extra, just return nil if actual soup call undef method
|
24
|
+
#describe "test actual soup call undef method" do
|
25
|
+
#it "must return nil" do
|
26
|
+
#"a".maybe.aaa.just.must_equal nil
|
27
|
+
#end
|
28
|
+
#end
|
29
|
+
|
30
|
+
describe "test actual soup" do
|
31
|
+
it "must return 2" do
|
32
|
+
2.maybe.to_s.just.must_equal "2"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "test method with parameters" do
|
37
|
+
it "must return false" do
|
38
|
+
"a".maybe.respond_to?("aaa").to_s.just.must_equal "false"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "test method #[]" do
|
43
|
+
it "must return 2" do
|
44
|
+
[1, 2, 3].maybe[1].to_s.just.must_equal "2"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: maybe_monad
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- liangjingyang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-05-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: another maybe monad library
|
47
|
+
email:
|
48
|
+
- simple.continue@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/maybe_monad.rb
|
59
|
+
- lib/maybe_monad/version.rb
|
60
|
+
- maybe_monad.gemspec
|
61
|
+
- maybe_monad.png
|
62
|
+
- spec/spec_maybe_monad.rb
|
63
|
+
homepage: ''
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.23
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: another maybe monad library
|
88
|
+
test_files:
|
89
|
+
- spec/spec_maybe_monad.rb
|