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:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}