Actions
Feature #21284
openRequest: add `Array#pad` method
    Feature #21284:
    Request: add `Array#pad` method
  
Status:
Open
Assignee:
-
Target version:
-
Description
A method to pad an array of arbitrary length with objects up to a specified array size does not currently exist.
Array#fill does not do this and I therefore propose the following method:
class Array
  def pad(pad_to_length, object = nil)
    fill(object, size, pad_to_length - size)
  end
end
I have provided an answer to a Stack Overflow question asking how this can be done in Ruby. I've also explained in a comment on the answer which suggests using Array#fill why this does not meet the exact need.
Actions