logic_or 0.1.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
- data/CHANGELOG.md +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/ext/logic_or/extconf.rb +6 -0
- data/ext/logic_or/logic_or.c +14 -0
- data/lib/logic_or.rb +10 -0
- data/lib/logic_or/version.rb +3 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1d61863c1a8405648dffc786fffdbdab25b1ead4
|
4
|
+
data.tar.gz: ca3ab85880d59bea55b627e9690327bcb70eb063
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2e89cb5693e99753b76153b72e9f00e83e02653a1efe2a31a02aa757d6d6744129ed262422fb30ba22f8d730434d0f41df8c2ebf7256e80f58183a8ac29349db
|
7
|
+
data.tar.gz: c4b8c967c64dc816c9ef2a0a41667a1ee0661811960b028018954c9d23cc467ca9b405a0818f812d4a58c09a936ed5313071b176a70fdd36987b16f0beca5ac2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Changelog
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Mauro Berlanda
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# LogicOr
|
2
|
+
|
3
|
+
[](https://travis-ci.com/mberlanda/logic_or)
|
4
|
+
|
5
|
+
The purpose of `LogicOr` gem is to provide the same behavior as *Logical Defined-Or operator* in perl:
|
6
|
+
<https://perldoc.perl.org/perlop.html#Logical-Defined-Or>
|
7
|
+
|
8
|
+
> Although it has no direct equivalent in C, Perl's `//` operator is related to its C-style "or". In fact, it's exactly the same as `||`, except that it tests the left hand side's definedness instead of its truth.
|
9
|
+
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'logic_or'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install logic_or
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Whilst `||` and `&&` operators will consider `nil` and `false` both as undefined, `lor` will allow
|
30
|
+
to make a distinction between them. This may be very tricky when assignin variables with `||=` or
|
31
|
+
`&&=`.
|
32
|
+
|
33
|
+
```rb
|
34
|
+
it { expect(nil.lor('a')).to eq('a') }
|
35
|
+
it { expect(nil.lor(1)).to eq(1) }
|
36
|
+
it { expect(nil.lor([])).to eq([]) }
|
37
|
+
it { expect(nil.lor(false)).to eq(false) }
|
38
|
+
|
39
|
+
it { expect(false.lor('a')).to eq(false) }
|
40
|
+
it { expect(false.lor(1)).to eq(false) }
|
41
|
+
it { expect(false.lor([])).to eq(false) }
|
42
|
+
it { expect(false.lor(true)).to eq(false) }
|
43
|
+
```
|
44
|
+
|
45
|
+
In v0.0.1 only the `lor` method is provided. As a next improvement it would be interesting to provide
|
46
|
+
as well a well to assign like `lor!` or `lor=`
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
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.
|
51
|
+
|
52
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mberlanda/logic_or. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
61
|
+
|
62
|
+
## Code of Conduct
|
63
|
+
|
64
|
+
Everyone interacting in the LogicOr project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mberlanda/logic_or/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
static VALUE
|
4
|
+
rb_logic_or(VALUE self, VALUE other)
|
5
|
+
{
|
6
|
+
return (self == Qnil ? other : self);
|
7
|
+
}
|
8
|
+
|
9
|
+
void
|
10
|
+
Init_logic_or()
|
11
|
+
{
|
12
|
+
VALUE rb_mLogicOr = rb_define_module("LogicOr");
|
13
|
+
rb_define_method(rb_mLogicOr, "lor", rb_logic_or, 1);
|
14
|
+
}
|
data/lib/logic_or.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logic_or
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mauro Berlanda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-02 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: '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: Provide Logical Defined-Or operator
|
56
|
+
email:
|
57
|
+
- mauro.berlanda@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions:
|
60
|
+
- ext/logic_or/extconf.rb
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- CHANGELOG.md
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- ext/logic_or/extconf.rb
|
67
|
+
- ext/logic_or/logic_or.c
|
68
|
+
- lib/logic_or.rb
|
69
|
+
- lib/logic_or/version.rb
|
70
|
+
homepage: https://github.com/mberlanda/logic_or
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
- ext
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.6.8
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Provide Logical Defined-Or operator
|
95
|
+
test_files: []
|