powertools 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/maybe_chain.rb +27 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40eb8ed3218a255bb1e3f3cd1e883f5ef33eb4feaad5b953d93074d3a55ed067
|
4
|
+
data.tar.gz: 8a077bb13f7a3ced89d470664265600334cf6bb0f642f679701d79d74ddf7d3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab8d7eccaae26072d8c328a4d282caebc5489518ff2655eb422dc767f9c2f1f982182ee4cddea0095fe23b2a7dca9b0210a5fcc6fd658dd2713461e19a16891e
|
7
|
+
data.tar.gz: b49a265e3f1c4cf745f80d9df8de4e0e950db6b4e171573eb36214384e924329909dc4f500e81289eef9894f54305fd590e7342cfc67177a0649eb985c2b3855
|
data/lib/maybe_chain.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
class Hash
|
2
|
+
def maybe_chain(args = [])
|
3
|
+
return nil unless self
|
4
|
+
|
5
|
+
r = self
|
6
|
+
args.each_with_index do |a, _i|
|
7
|
+
return nil if r[a].nil? || (r.class != Hash && r.class != Array)
|
8
|
+
|
9
|
+
r = a.instance_of?(Range) ? a.map { |i| r[i] } : r[a]
|
10
|
+
end
|
11
|
+
r
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Array
|
16
|
+
def maybe_chain(args = [])
|
17
|
+
return nil unless self
|
18
|
+
|
19
|
+
r = self
|
20
|
+
args.each_with_index do |a, _i|
|
21
|
+
return nil if r[a].nil? || (r.class != Hash && r.class != Array)
|
22
|
+
|
23
|
+
r = a.instance_of?(Range) ? a.map { |i| r[i] } : r[a]
|
24
|
+
end
|
25
|
+
r
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: powertools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- C. Kinniburgh
|
@@ -16,6 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/maybe_chain.rb
|
19
20
|
- lib/range.rb
|
20
21
|
homepage: http://github.com/cjkinni/powertools
|
21
22
|
licenses:
|
@@ -39,5 +40,5 @@ requirements: []
|
|
39
40
|
rubygems_version: 3.2.22
|
40
41
|
signing_key:
|
41
42
|
specification_version: 4
|
42
|
-
summary: A
|
43
|
+
summary: A set of small improvements to Ruby classes
|
43
44
|
test_files: []
|