Sha256: 7941cfcc9a66d8bd3e86ae3488d9813877caf13236d65c3e4c6e030ed471fdda
Contents?: true
Size: 1.1 KB
Versions: 115
Compression:
Stored size: 1.1 KB
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 fill. # # together_fill has alias :tfill # # not use block case # lists = [[*1..5], [*6..10]] # ret = lists.together_fill(99) # print ret # => [[99, 99, 99, 99, 99], [99, 99, 99, 99, 99]] # # use block, no args case # lists = [[*1..5], [*6..10]] # ret = lists.together_fill { |i|(i + 1) + 1 } # print ret # => [[2, 3, 4, 5, 6], [2, 3, 4, 5, 6]] # # use block, has args case # lists = [[*1..5], [*6..10]] # ret = lists.together_fill(2) { |i|(i + 1) + 1 } # print ret # => [[1, 2, 4, 5, 6], [6, 7, 4, 5, 6]] def together_fill(fill_value = nil, &block) if_not_contain_array_rails_type_error if block fill_value = 0 if fill_value.nil? first.each_with_index do |i_v, i| next if i < fill_value each { |list|list[i] = yield(i) } end else each { |list|list.fill fill_value } end self end alias_method :tfill, :together_fill end
Version data entries
115 entries across 115 versions & 1 rubygems