tbpgr_utils 0.0.42 → 0.0.43
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +32 -0
- data/lib/open_classes/array/together_slice.rb +38 -0
- data/lib/open_classes/array.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/open_classes/array/together_slice_spec.rb +75 -0
- metadata +15 -12
data/README.md
CHANGED
@@ -50,6 +50,7 @@ Or install it yourself as:
|
|
50
50
|
|[TbpgrUtils Array#together_select](#arraytogether_selector-tselect-together_find_all-tfindall) |together version of Enumerable#select. together_select has aliases [:tselect, :together_find_all, :tfindall] |
|
51
51
|
|[TbpgrUtils Array#together_shift](#arraytogether_shift) |together version of Array#shift. together_shift has alias :tshift |
|
52
52
|
|[TbpgrUtils Array#together_shuffle](#arraytogether_shuffleor-tshuffle) |together version of Array#shuffle. together_shuffle has alias :tshuffle |
|
53
|
+
|[TbpgrUtils Array#together_slice](#arraytogether_sliceor-tslice) |together version of Array#slice. together_slice has alias :tslice |
|
53
54
|
|[TbpgrUtils Array#together_with_index](#arraytogether_with_index) |loop all arrays by block with index |
|
54
55
|
|[AttributesHashable.to_hash](#attributeshashableto_hash) |define to_hash method for get instance_values |
|
55
56
|
|[AttributesInitializable::ClassMethods.attr_accessor_init](#attributesinitializableclassmethodsattr_accessor_init) |generate attr_accessor + initializer |
|
@@ -849,6 +850,36 @@ print ret # => [[1 or 2, 1 or 2], [5 or 6, 5 or 6]]
|
|
849
850
|
|
850
851
|
[back to list](#list)
|
851
852
|
|
853
|
+
### Array#together_slice(or :tslice)
|
854
|
+
single args case
|
855
|
+
~~~ruby
|
856
|
+
require 'tbpgr_utils'
|
857
|
+
|
858
|
+
lists = [[*1..5], [*6..10]]
|
859
|
+
ret = lists.together_slice 2
|
860
|
+
print ret # => [3, 8]
|
861
|
+
~~~
|
862
|
+
|
863
|
+
multi args case
|
864
|
+
~~~ruby
|
865
|
+
require 'tbpgr_utils'
|
866
|
+
|
867
|
+
lists = [[*1..5], [*6..10]]
|
868
|
+
ret = lists.together_slice 2, 2
|
869
|
+
print ret # => [[3, 4], [8, 9]]
|
870
|
+
~~~
|
871
|
+
|
872
|
+
range args case
|
873
|
+
~~~ruby
|
874
|
+
require 'tbpgr_utils'
|
875
|
+
|
876
|
+
lists = [[*1..5], [*6..10]]
|
877
|
+
ret = lists.together_slice (2..3)
|
878
|
+
print ret # => [[3, 4], [8, 9]]
|
879
|
+
~~~
|
880
|
+
|
881
|
+
[back to list](#list)
|
882
|
+
|
852
883
|
### Array#together_with_index
|
853
884
|
~~~ruby
|
854
885
|
require 'tbpgr_utils'
|
@@ -1625,6 +1656,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
1625
1656
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
1626
1657
|
|
1627
1658
|
## History
|
1659
|
+
* version 0.0.43 : add Array#together_slice(alias tslice).
|
1628
1660
|
* version 0.0.42 : add MetasyntacticVariable
|
1629
1661
|
* version 0.0.41 : add Object#guard, unless_guard
|
1630
1662
|
* version 0.0.40 : add Kernel#aa_ancestors.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'open_classes/array/together_helper'
|
3
|
+
|
4
|
+
# Array
|
5
|
+
class Array
|
6
|
+
include TogetherHelper
|
7
|
+
|
8
|
+
# Arrays bulk slice.
|
9
|
+
#
|
10
|
+
# together_slice has alias :tslice
|
11
|
+
#
|
12
|
+
# === Examples
|
13
|
+
#
|
14
|
+
# single args case
|
15
|
+
#
|
16
|
+
# lists = [[*1..5], [*6..10]]
|
17
|
+
# ret = lists.together_slice 2
|
18
|
+
# print ret # => [3, 8]
|
19
|
+
#
|
20
|
+
# multi args case
|
21
|
+
#
|
22
|
+
# lists = [[*1..5], [*6..10]]
|
23
|
+
# ret = lists.together_slice 2, 2
|
24
|
+
# print ret # => [[3, 4], [8, 9]]
|
25
|
+
#
|
26
|
+
# range args case
|
27
|
+
#
|
28
|
+
# lists = [[*1..5], [*6..10]]
|
29
|
+
# ret = lists.together_slice (2..3)
|
30
|
+
# print ret # => [[3, 4], [8, 9]]
|
31
|
+
#
|
32
|
+
def together_slice(*args)
|
33
|
+
if_not_contain_array_rails_type_error
|
34
|
+
reduce([]) { |ret, list|ret << list.slice(*args) }
|
35
|
+
end
|
36
|
+
|
37
|
+
alias_method :tslice, :together_slice
|
38
|
+
end
|
data/lib/open_classes/array.rb
CHANGED
@@ -22,4 +22,5 @@ require 'open_classes/array/together_sample'
|
|
22
22
|
require 'open_classes/array/together_select'
|
23
23
|
require 'open_classes/array/together_shift'
|
24
24
|
require 'open_classes/array/together_shuffle'
|
25
|
+
require 'open_classes/array/together_slice'
|
25
26
|
require 'open_classes/array/together_with_index'
|
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'active_support/core_ext/object/inclusion'
|
4
|
+
require 'tbpgr_utils'
|
5
|
+
|
6
|
+
describe Array do
|
7
|
+
context :together_slice do
|
8
|
+
cases = [
|
9
|
+
{
|
10
|
+
case_no: 1,
|
11
|
+
case_title: 'single args case',
|
12
|
+
inputs: [[*1..5], [*6..10]],
|
13
|
+
method_name: 'together_slice',
|
14
|
+
args1: 2,
|
15
|
+
expected: [3, 8],
|
16
|
+
},
|
17
|
+
{
|
18
|
+
case_no: 2,
|
19
|
+
case_title: 'multi args case',
|
20
|
+
inputs: [[*1..5], [*6..10]],
|
21
|
+
method_name: 'together_slice',
|
22
|
+
args1: 2,
|
23
|
+
args2: 2,
|
24
|
+
expected: [[3, 4], [8, 9]],
|
25
|
+
},
|
26
|
+
{
|
27
|
+
case_no: 3,
|
28
|
+
case_title: 'range args case',
|
29
|
+
inputs: [[*1..5], [*6..10]],
|
30
|
+
method_name: 'together_slice',
|
31
|
+
args1: (2..3),
|
32
|
+
expected: [[3, 4], [8, 9]],
|
33
|
+
},
|
34
|
+
{
|
35
|
+
case_no: 4,
|
36
|
+
case_title: 'single args case(alias tslice)',
|
37
|
+
inputs: [[*1..5], [*6..10]],
|
38
|
+
method_name: 'tslice',
|
39
|
+
args1: 2,
|
40
|
+
expected: [3, 8],
|
41
|
+
},
|
42
|
+
]
|
43
|
+
|
44
|
+
cases.each do |c|
|
45
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
46
|
+
begin
|
47
|
+
case_before c
|
48
|
+
|
49
|
+
# -- given --
|
50
|
+
# nothing
|
51
|
+
|
52
|
+
# -- when --
|
53
|
+
if c[:args2]
|
54
|
+
actual = c[:inputs].send c[:method_name], c[:args1], c[:args2]
|
55
|
+
else
|
56
|
+
actual = c[:inputs].send c[:method_name], c[:args1]
|
57
|
+
end
|
58
|
+
|
59
|
+
# -- then --
|
60
|
+
expect(actual).to eq(c[:expected])
|
61
|
+
ensure
|
62
|
+
case_after c
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def case_before(c)
|
67
|
+
# implement each case before
|
68
|
+
end
|
69
|
+
|
70
|
+
def case_after(c)
|
71
|
+
# implement each case after
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tbpgr_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.43
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-02-
|
12
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &22251216 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 4.0.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *22251216
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &22250712 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.3'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *22250712
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &22249848 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *22249848
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &22249212 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.14.1
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *22249212
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &22248300 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.8.2
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *22248300
|
69
69
|
description: Utilities
|
70
70
|
email:
|
71
71
|
- tbpgr@tbpgr.jp
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/open_classes/array/together_select.rb
|
112
112
|
- lib/open_classes/array/together_shift.rb
|
113
113
|
- lib/open_classes/array/together_shuffle.rb
|
114
|
+
- lib/open_classes/array/together_slice.rb
|
114
115
|
- lib/open_classes/array/together_with_index.rb
|
115
116
|
- lib/open_classes/file.rb
|
116
117
|
- lib/open_classes/kernel.rb
|
@@ -160,6 +161,7 @@ files:
|
|
160
161
|
- spec/open_classes/array/together_select_spec.rb
|
161
162
|
- spec/open_classes/array/together_shift_spec.rb
|
162
163
|
- spec/open_classes/array/together_shuffle_spec.rb
|
164
|
+
- spec/open_classes/array/together_slice_spec.rb
|
163
165
|
- spec/open_classes/array/together_spec.rb
|
164
166
|
- spec/open_classes/array/together_with_index_spec.rb
|
165
167
|
- spec/open_classes/file_spec.rb
|
@@ -233,6 +235,7 @@ test_files:
|
|
233
235
|
- spec/open_classes/array/together_select_spec.rb
|
234
236
|
- spec/open_classes/array/together_shift_spec.rb
|
235
237
|
- spec/open_classes/array/together_shuffle_spec.rb
|
238
|
+
- spec/open_classes/array/together_slice_spec.rb
|
236
239
|
- spec/open_classes/array/together_spec.rb
|
237
240
|
- spec/open_classes/array/together_with_index_spec.rb
|
238
241
|
- spec/open_classes/file_spec.rb
|