Sha256: de825a9a346c2dd1ef04d056f6136bff54412a9b077698627c9d1d2f670c13a1
Contents?: true
Size: 984 Bytes
Versions: 115
Compression:
Stored size: 984 Bytes
Contents
# encoding: utf-8 require 'open_classes/object' require 'open_classes/module' require 'open_classes/array/together_helper' # Array class Array include TogetherHelper # Arrays bulk insert. # # together_insert has alias :tinsert # # both insert exist case # lists = [[*1..5], [*5..9]] # ret = lists.together_insert(1, 55, 66) # print ret # => [[1, 55, 66, 2, 3, 4, 5], [5, 55, 66, 6, 7, 8, 9]] # # both insert exist and minus index case # lists = [[*1..5], [*5..9]] # ret = lists.together_insert(-2, 55, 66) # print ret # => [[1, 2, 3, 4, 55, 66, 5], [5, 6, 7, 8, 55, 66, 9]] # # both insert exist case # lists = [[*1..5], [*5..9]] # ret = lists.together_insert(6, 55, 66) # print ret # => [[1, 2, 3, 4, 5, nil, 55, 66], [5, 6, 7, 8, 9, nil, 55, 66]], def together_insert(index, *args) if_not_contain_array_rails_type_error each { |list|list.insert(index, *args) } end alias_method :tinsert, :together_insert end
Version data entries
115 entries across 115 versions & 1 rubygems