therefore 1.0.1 → 1.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +26 -0
- data/lib/therefore/kernel_patch.rb +8 -0
- data/lib/therefore/version.rb +1 -1
- data/sig/therefore.rbs +3 -0
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d246d3dec40b144695422a6bed485e924ba24c594ecc153dc6ec82603de37ca
|
|
4
|
+
data.tar.gz: c254bcc43eede3650a00593f9d85baf6bdb146c6d7d12fe62eb901844c8af85d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 913bd179a56a3548f09574a8a4732d127d35683b55a1242b70cebf5199a01af67f9a1514e78e310b60a572df7b4578650414fb3c826d26b29da5412ab9c97876
|
|
7
|
+
data.tar.gz: bc9a8140e5029e302212aec60916b72d63036e7220e3758ebf895ed12dd271a2035b0fbc6ed391689b634ac3e03627f0050c895d85aaee545c10d3a6ad499d99
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -26,6 +26,8 @@ gem install therefore
|
|
|
26
26
|
|
|
27
27
|
## Usage
|
|
28
28
|
|
|
29
|
+
### `therefore` and `otherwise`
|
|
30
|
+
|
|
29
31
|
`obj.therefore {...}` will invoke the block, yielding `obj` to it, unless `obj` is either `nil` or `false`. If the block is invoked its result is returned, otherwise `obj` is returned:
|
|
30
32
|
|
|
31
33
|
```ruby
|
|
@@ -81,6 +83,30 @@ nil.otherwise.to_a # => [nil]
|
|
|
81
83
|
'string'.otherwise.to_a # => []
|
|
82
84
|
```
|
|
83
85
|
|
|
86
|
+
### `if` and `unless`
|
|
87
|
+
|
|
88
|
+
Let's consider a regular `if...end` conditional:
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
if condition
|
|
92
|
+
expression
|
|
93
|
+
end
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`therefore` and `otherwise` abstract away the condition, relying on the implicit "is it nil/false?", and use the block for the expression.
|
|
97
|
+
|
|
98
|
+
`if` and `unless` do the opposite: they use the block for the condition, and return the receiver or `nil` depending on the result.
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
request
|
|
102
|
+
.if(&:open?)
|
|
103
|
+
&.close!
|
|
104
|
+
|
|
105
|
+
# is equivalent to
|
|
106
|
+
|
|
107
|
+
request.close! if request.open?
|
|
108
|
+
```
|
|
109
|
+
|
|
84
110
|
## Version numbers
|
|
85
111
|
|
|
86
112
|
Therefore loosely follows [Semantic Versioning](https://semver.org/), with a hard guarantee that breaking changes to the public API will always coincide with an increase to the `MAJOR` number.
|
data/lib/therefore/version.rb
CHANGED
data/sig/therefore.rbs
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: therefore
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Moku S.r.l.
|
|
8
8
|
- Riccardo Agatea
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: exe
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies: []
|
|
14
13
|
description: Just like each, therefore relies on block semantics, so it's essentially
|
|
15
14
|
an if conditional with a scope, a closure, and the ability to be chained with other
|
|
@@ -40,7 +39,6 @@ metadata:
|
|
|
40
39
|
homepage_uri: https://github.com/moku-io/therefore
|
|
41
40
|
source_code_uri: https://github.com/moku-io/therefore
|
|
42
41
|
changelog_uri: https://github.com/moku-io/therefore/blob/master/CHANGELOG.md
|
|
43
|
-
post_install_message:
|
|
44
42
|
rdoc_options: []
|
|
45
43
|
require_paths:
|
|
46
44
|
- lib
|
|
@@ -55,8 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
55
53
|
- !ruby/object:Gem::Version
|
|
56
54
|
version: '0'
|
|
57
55
|
requirements: []
|
|
58
|
-
rubygems_version: 3.
|
|
59
|
-
signing_key:
|
|
56
|
+
rubygems_version: 3.6.7
|
|
60
57
|
specification_version: 4
|
|
61
58
|
summary: A simple wrapper for if conditionals, what each is for while loops.
|
|
62
59
|
test_files: []
|