Over a million developers have joined DZone.

Fill The Missing Blanks In An Array

·
If we have an array which has only 2 items yet we expected 4 items we can use Array#fill to complete it e.g.

r = %w(b c)       # => ["b", "c"]
r.fill('a', 2..3) # => ["b", "c", "a", "a"]


Resources:
 - Class: Array [ruby-doc.org]
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}