nrser 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d78b1a617d1df6e4d06f5fd87dbcfedac286086f
4
- data.tar.gz: 533332e21ab77f0c9be0a0d88b7acf0af91fec53
3
+ metadata.gz: bce188e694cb5fd687f3085a43602dc303a1c1ab
4
+ data.tar.gz: affc25e12e51d899523c3a5fe5db6c498a997d8b
5
5
  SHA512:
6
- metadata.gz: 774841218eba88ac41db6ce8d515b3a6617ac6cf0fe0e24280ddb0a151428a5dcd5d1a2d9d290c5303992b8570a65a2e3666652c5b7265fe607eb4c4b98dd25d
7
- data.tar.gz: e8d733ee8bf6cea47a6f93c7d356fcc850d8e434bc5566196fb2d7559d4ff9d2360728a259fc7ecd615620b68024002cd49ea46d84559da10aa815142c0e7dd6
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
- # Return an array given any value in the way that makes most sense:
3
+ # Eigenclass (Singleton Class)
4
+ # ========================================================================
4
5
  #
5
- # 1. If `value` is an array, return it.
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
- if value.respond_to? :to_a
28
- begin
29
- return value.to_a
30
- rescue
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
- end
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
- [value]
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
@@ -1,5 +1,5 @@
1
1
  module NRSER
2
- VERSION = "0.0.22"
2
+ VERSION = "0.0.23"
3
3
 
4
4
  module Version
5
5
 
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.22
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-16 00:00:00.000000000 Z
11
+ date: 2017-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler