tbpgr_utils 0.0.31 → 0.0.32

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.
data/README.md CHANGED
@@ -34,6 +34,7 @@ Or install it yourself as:
34
34
  |[TbpgrUtils Array#together_first](#arraytogether_first) |together version of Array#first. together_first has alias :tfirst |
35
35
  |[TbpgrUtils Array#together_include?](#arraytogether_include) |together version of Array#include?. together_include? has alias :tinclude? |
36
36
  |[TbpgrUtils Array#together_index](#arraytogether_index) |together version of Array#index. together_index has alias :tindex |
37
+ |[TbpgrUtils Array#together_insert](#arraytogether_insert) |together version of Array#insert. together_insert has alias :tinsert |
37
38
  |[TbpgrUtils Array#together_map](#arraytogether_mapor-tmap-together_collect-tcollect) |together version of Enumerable#map. together_map has aliases [:tmap, :together_collect, :tcollect] |
38
39
  |[TbpgrUtils Array#together_map!](#arraytogether_map-1or-tmap-1-together_collect-1-tcollect-1) |together version of Enumerable#map!. together_map! has aliases [:tmap!, :together_collect!, :tcollect!] |
39
40
  |[TbpgrUtils Array#together_reduce](#arraytogether_reduceor-treduce-together_inject-tinject) |together version of Enumerable#reduce. together_reduce has aliases [:treduce, :together_inject, :tinject] |
@@ -405,6 +406,32 @@ print ret # => [nil, nil]
405
406
 
406
407
  [back to list](#list)
407
408
 
409
+ ### Array#together_insert
410
+ together_insert has alias :tinsert
411
+
412
+ both insert exist case
413
+ ~~~ruby
414
+ lists = [[*1..5], [*5..9]]
415
+ ret = lists.together_insert(1, 55, 66)
416
+ print ret # => [[1, 55, 66, 2, 3, 4, 5], [5, 55, 66, 6, 7, 8, 9]]
417
+ ~~~
418
+
419
+ both insert exist and minus index case
420
+ ~~~ruby
421
+ lists = [[*1..5], [*5..9]]
422
+ ret = lists.together_insert(-2, 55, 66)
423
+ print ret # => [[1, 2, 3, 4, 55, 66, 5], [5, 6, 7, 8, 55, 66, 9]]
424
+ ~~~
425
+
426
+ both insert exist case
427
+ ~~~ruby
428
+ lists = [[*1..5], [*5..9]]
429
+ ret = lists.together_insert(6, 55, 66)
430
+ print ret # => [[1, 2, 3, 4, 5, nil, 55, 66], [5, 6, 7, 8, 9, nil, 55, 66]],
431
+ ~~~
432
+
433
+ [back to list](#list)
434
+
408
435
  ### Array#together_map(or tmap, together_collect, tcollect)
409
436
  ~~~ruby
410
437
  require 'tbpgr_utils'
@@ -1148,6 +1175,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
1148
1175
  https://github.com/tbpgr/tbpgr_utils_snippets
1149
1176
 
1150
1177
  ## History
1178
+ * version 0.0.32 : add Array#together_insert(alias tinsert).
1151
1179
  * version 0.0.31 : add Array#together_index(alias tindex).
1152
1180
  * version 0.0.30 : add Array#together_include?(alias tinclude?).
1153
1181
  * version 0.0.29 : add Array#together_first(alias tfirst).
@@ -481,6 +481,29 @@ class Array
481
481
  reduce([]) { |ret, list|ret << list.index(value) }
482
482
  end
483
483
 
484
+ # Arrays bulk insert.
485
+ #
486
+ # together_insert has alias :tinsert
487
+ #
488
+ # both insert exist case
489
+ # lists = [[*1..5], [*5..9]]
490
+ # ret = lists.together_insert(1, 55, 66)
491
+ # print ret # => [[1, 55, 66, 2, 3, 4, 5], [5, 55, 66, 6, 7, 8, 9]]
492
+ #
493
+ # both insert exist and minus index case
494
+ # lists = [[*1..5], [*5..9]]
495
+ # ret = lists.together_insert(-2, 55, 66)
496
+ # print ret # => [[1, 2, 3, 4, 55, 66, 5], [5, 6, 7, 8, 55, 66, 9]]
497
+ #
498
+ # both insert exist case
499
+ # lists = [[*1..5], [*5..9]]
500
+ # ret = lists.together_insert(6, 55, 66)
501
+ # print ret # => [[1, 2, 3, 4, 5, nil, 55, 66], [5, 6, 7, 8, 9, nil, 55, 66]],
502
+ def together_insert(index, *args)
503
+ if_not_contain_array_rails_type_error
504
+ each { |list|list.insert(index, *args) }
505
+ end
506
+
484
507
  private
485
508
 
486
509
  def if_not_contain_array_rails_type_error
@@ -541,6 +564,7 @@ class Array
541
564
  alias_method :tfirst, :together_first
542
565
  alias_method :tinclude?, :together_include?
543
566
  alias_method :tindex, :together_index
567
+ alias_method :tinsert, :together_insert
544
568
  alias_methods [:together_collect, :tmap, :tcollect], :together_map
545
569
  alias_methods [:together_collect!, :tmap!, :tcollect!], :together_map!
546
570
  alias_methods [:together_find_all, :tselect, :tfindall], :together_select
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.31'
5
+ VERSION = '0.0.32'
6
6
  end