nil_or 0.0.1 → 1.0.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/README.md +40 -0
- data/lib/nil_or.rb +2 -2
- data/nil_or.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1a0af38e63fb8dc2790570ee5297eb7ad07a161
|
4
|
+
data.tar.gz: 2b6f8cfe4040142bf4273c254915781b1747266e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad1a4dcfec50cfe3d85ea58f53b14f3bc6f32165d1805df0a8ddee2a704b623d7b820908a1a6c9f079aec80e54d4ab64acf9f3358af42b411849ef1093159676
|
7
|
+
data.tar.gz: 48a0bba734760dd9df498da05b14c296835867d4e26d0defeacad8d3836e48d87ce9e0f477942e279f0c5ce4e943c6781f9724ddbea9ee049d2be8c06faf7fda
|
data/README.md
CHANGED
@@ -1 +1,41 @@
|
|
1
1
|
# nil_or
|
2
|
+
|
3
|
+
Delegates methods to the target unless nil.
|
4
|
+
|
5
|
+
## Getting started
|
6
|
+
|
7
|
+
$ gem install nil_or
|
8
|
+
|
9
|
+
Or in your Gemfile:
|
10
|
+
|
11
|
+
gem "nil_or"
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
When am I going to need it? Instead of writing:
|
16
|
+
|
17
|
+
date_of_birth = params[:date_of_birth] ? params[:date_of_birth].to_date : nil
|
18
|
+
|
19
|
+
Write:
|
20
|
+
|
21
|
+
date_of_birth = params[:date_of_birth].nil_or.to_date
|
22
|
+
|
23
|
+
When x is not nil:
|
24
|
+
|
25
|
+
x = 5
|
26
|
+
x.nil_or.to_s
|
27
|
+
=> "5"
|
28
|
+
x.nil_or + 2
|
29
|
+
=> 7
|
30
|
+
x.nil_or.times { |i| puts i }
|
31
|
+
...
|
32
|
+
|
33
|
+
But when it is nil:
|
34
|
+
|
35
|
+
x = nil
|
36
|
+
x.nil_or.to_s
|
37
|
+
=> nil
|
38
|
+
x.nil_or + 2
|
39
|
+
=> nil
|
40
|
+
x.nil_or.shakalaka(1, 2) { does_nothing }
|
41
|
+
=> nil
|
data/lib/nil_or.rb
CHANGED
data/nil_or.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nil_or
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oded Niv
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Delegates methods to the object or returns nil.
|
14
14
|
email:
|