DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Fill The Missing Blanks In An Array

  • submit to reddit
        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"]

 - <a href="">Class: Array</a> []