nrser 0.0.22 → 0.0.23
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/lib/nrser/array.rb +51 -30
- data/lib/nrser/refinements/array.rb +10 -0
- data/lib/nrser/version.rb +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: bce188e694cb5fd687f3085a43602dc303a1c1ab
|
4
|
+
data.tar.gz: affc25e12e51d899523c3a5fe5db6c498a997d8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1946f2af31a5f40a84533d114d02513729308eb7ba06d3a2fd2f57ed1d4326718432a9aff3e64bb8be1e38703ffe1663bacc0ba0beeb67b68018472b2c8ab941
|
7
|
+
data.tar.gz: '08ac5aff6d524538547eef3b00e07aa916301b83bb6812980af20d341c714a25dfcd0d1a8957cf939fd112becdac7b3182507c20c97913d56b08888d7639d60e'
|
data/lib/nrser/array.rb
CHANGED
@@ -1,37 +1,58 @@
|
|
1
|
-
module NRSER
|
1
|
+
module NRSER
|
2
2
|
|
3
|
-
#
|
3
|
+
# Eigenclass (Singleton Class)
|
4
|
+
# ========================================================================
|
4
5
|
#
|
5
|
-
|
6
|
-
#
|
7
|
-
# 2. If `value` is `nil`, return `[]`.
|
8
|
-
#
|
9
|
-
# 3. If `value` responds to `#to_a`, try calling it. If it succeeds, return
|
10
|
-
# that.
|
11
|
-
#
|
12
|
-
# 4. Return an array with `value` as it's only item.
|
13
|
-
#
|
14
|
-
# Refinement
|
15
|
-
# ----------
|
16
|
-
#
|
17
|
-
# Added to `Object` in `nrser/refinements`.
|
18
|
-
#
|
19
|
-
# @param [Object] value
|
20
|
-
#
|
21
|
-
# @return [Array]
|
22
|
-
#
|
23
|
-
def self.as_array value
|
24
|
-
return value if value.is_a? Array
|
25
|
-
return [] if value.nil?
|
6
|
+
class << self
|
26
7
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
8
|
+
# Return an array given any value in the way that makes most sense:
|
9
|
+
#
|
10
|
+
# 1. If `value` is an array, return it.
|
11
|
+
#
|
12
|
+
# 2. If `value` is `nil`, return `[]`.
|
13
|
+
#
|
14
|
+
# 3. If `value` responds to `#to_a`, try calling it. If it succeeds, return
|
15
|
+
# that.
|
16
|
+
#
|
17
|
+
# 4. Return an array with `value` as it's only item.
|
18
|
+
#
|
19
|
+
# Refinement
|
20
|
+
# ----------
|
21
|
+
#
|
22
|
+
# Added to `Object` in `nrser/refinements`.
|
23
|
+
#
|
24
|
+
# @param [Object] value
|
25
|
+
#
|
26
|
+
# @return [Array]
|
27
|
+
#
|
28
|
+
def as_array value
|
29
|
+
return value if value.is_a? Array
|
30
|
+
return [] if value.nil?
|
31
|
+
|
32
|
+
if value.respond_to? :to_a
|
33
|
+
begin
|
34
|
+
return value.to_a
|
35
|
+
rescue
|
36
|
+
end
|
31
37
|
end
|
32
|
-
|
38
|
+
|
39
|
+
[value]
|
40
|
+
end # #as_array
|
41
|
+
|
42
|
+
|
43
|
+
# Functional implementation of "rest" for arrays. Used when refining `#rest`
|
44
|
+
# into {Array}.
|
45
|
+
#
|
46
|
+
# @param [Array] array
|
47
|
+
#
|
48
|
+
# @return [return_type]
|
49
|
+
# New array consisting of all elements after the first.
|
50
|
+
#
|
51
|
+
def rest array
|
52
|
+
array[1..-1]
|
53
|
+
end # #rest
|
54
|
+
|
33
55
|
|
34
|
-
|
35
|
-
end # .as_array
|
56
|
+
end # class << self (Eigenclass)
|
36
57
|
|
37
58
|
end # module NRSER
|
@@ -3,5 +3,15 @@ require_relative './enumerable'
|
|
3
3
|
module NRSER
|
4
4
|
refine ::Array do
|
5
5
|
include NRSER::Refinements::Enumerable
|
6
|
+
|
7
|
+
|
8
|
+
# @return [Array]
|
9
|
+
# new array consisting of all elements after the first (which may be
|
10
|
+
# none, resulting in an empty array).
|
11
|
+
#
|
12
|
+
def rest
|
13
|
+
NRSER.rest self
|
14
|
+
end # #rest
|
15
|
+
|
6
16
|
end # refine ::Array
|
7
17
|
end # NRSER
|
data/lib/nrser/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nrser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nrser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|