array_include_methods 1.1.0 → 1.2.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 +4 -0
- data/README.md +26 -11
- data/VERSION +1 -1
- data/array_include_methods.gemspec +2 -2
- data/lib/array_include_methods.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 925807376e5d7c387227dc33369fa80dcefd7abc7f4164f5ed939e8de9a0fa66
|
4
|
+
data.tar.gz: 5a316e7e928da5eb1028e626fbcdec588e21fc66d683afec48278da7bdcc5899
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e50f5e30e11b7e2c19234fe207c436b87ee37ff690212af30eb9460eab789ba08dc06b545d55aa2d41d80ccaf2a97f37c6ee2dfeaac31f7d53be55b1ccb7b26
|
7
|
+
data.tar.gz: 9de14d6773e0f55527f6857fb72c75be710615cc02eb61fcf297ca00d3ee2db3d9b9a2e6fea05ebde468497d79a66a38996bd2f1877b0f9813b798b94b93d1dc
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ArrayIncludeMethods 1.
|
1
|
+
# ArrayIncludeMethods 1.2.0 - Ruby Refinement
|
2
2
|
[](http://badge.fury.io/rb/array_include_methods)
|
3
3
|
[](https://travis-ci.com/AndyObtiva/array_include_methods)
|
4
4
|
[](https://coveralls.io/github/AndyObtiva/array_include_methods?branch=master)
|
@@ -12,7 +12,7 @@
|
|
12
12
|
Include the following in Gemfile:
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
gem 'array_include_methods', '~> 1.
|
15
|
+
gem 'array_include_methods', '~> 1.2.0'
|
16
16
|
```
|
17
17
|
|
18
18
|
Run:
|
@@ -26,7 +26,7 @@ bundle
|
|
26
26
|
Run:
|
27
27
|
|
28
28
|
```
|
29
|
-
gem install array_include_methods -v1.
|
29
|
+
gem install array_include_methods -v1.2.0
|
30
30
|
```
|
31
31
|
|
32
32
|
## Usage
|
@@ -47,7 +47,18 @@ Now, you have `#include_all?` and `#include_any?` methods on `Array` objects.
|
|
47
47
|
|
48
48
|
## Examples
|
49
49
|
|
50
|
-
### `Array#
|
50
|
+
### `Array#include_any?(*other_array)`
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
[1, 2, 3, 4].include_any?(2, 4, 5) # returns true
|
54
|
+
[1, 2, 3, 4].include_any?([2, 4, 5]) # returns true
|
55
|
+
[1, 2, 3, 4].include_any?(6, 7) # returns false
|
56
|
+
[1, 2, 3, 4].include_any?([6, 7]) # returns false
|
57
|
+
[1, 2, 3, 4].include_any?([]) # returns true
|
58
|
+
[1, 2, 3, 4].include_any?(nil) # returns false
|
59
|
+
```
|
60
|
+
|
61
|
+
### `Array#include_all?(*other_array)`
|
51
62
|
|
52
63
|
```ruby
|
53
64
|
[1, 2, 3, 4].include_all?(2, 3) # returns true
|
@@ -64,15 +75,19 @@ Now, you have `#include_all?` and `#include_any?` methods on `Array` objects.
|
|
64
75
|
[1, 2, 3, 4].include_all?(nil) # returns false
|
65
76
|
```
|
66
77
|
|
67
|
-
### `Array#
|
78
|
+
### `Array#array_index(other_array)`
|
79
|
+
|
80
|
+
Returns first array index of `other_array` in `first_array` assuming `first_array.include_all?(other_array)` returns true
|
68
81
|
|
69
82
|
```ruby
|
70
|
-
[1, 2, 3, 4].
|
71
|
-
[1, 2, 3, 4].
|
72
|
-
[1, 2, 3, 4].
|
73
|
-
[1, 2, 3, 4].
|
74
|
-
[1, 2, 3, 4].
|
75
|
-
[1, 2, 3, 4].
|
83
|
+
[1, 2, 3, 4].array_index([2, 3, 4]) # returns 1
|
84
|
+
[1, 2, 3, 4].array_index([2, 3]) # returns 1
|
85
|
+
[1, 2, 3, 4].array_index([3, 4]) # returns 2
|
86
|
+
[1, 2, 3, 4].array_index([2, 4]) # returns -1
|
87
|
+
[1, 2, 3, 4].array_index([4, 2]) # returns -1
|
88
|
+
[1, 2, 3, 4].array_index([2, 4, 5]) # returns -1
|
89
|
+
[1, 2, 3, 4].array_index([]) # returns -1
|
90
|
+
[1, 2, 3, 4].array_index(nil) # returns -1
|
76
91
|
```
|
77
92
|
|
78
93
|
## Opal Compatibility
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: array_include_methods 1.
|
5
|
+
# stub: array_include_methods 1.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "array_include_methods".freeze
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
@@ -53,6 +53,21 @@ module ArrayIncludeMethods
|
|
53
53
|
array = array[0] if array.size == 1 && array[0].is_a?(Array)
|
54
54
|
!array.nil? && (array.empty? || !(self & array).empty?)
|
55
55
|
end
|
56
|
+
|
57
|
+
def array_index(array)
|
58
|
+
result_array_index = -1
|
59
|
+
return result_array_index if array.nil?
|
60
|
+
if array.size <= self.size
|
61
|
+
size_diff = self.size - array.size
|
62
|
+
current_array_index = nil
|
63
|
+
result = (size_diff + 1).times.any? do |start_index|
|
64
|
+
current_array_index = start_index
|
65
|
+
self[start_index, array.size] == array
|
66
|
+
end
|
67
|
+
result_array_index = current_array_index if result
|
68
|
+
end
|
69
|
+
result_array_index
|
70
|
+
end
|
56
71
|
end
|
57
72
|
end
|
58
73
|
if RUBY_PLATFORM == 'opal'
|