Skip to content

Instantly share code, notes, and snippets.

@libkazz
Created August 10, 2014 03:04
Show Gist options
  • Save libkazz/75a032e89c016ffcde0a to your computer and use it in GitHub Desktop.
Save libkazz/75a032e89c016ffcde0a to your computer and use it in GitHub Desktop.
fill with nil
# Fill with nil, until list will be the size.
#
# [:a].nilfil(4) #=> [:a, nil, nil, nil, nil]
# [:a,:b,:b,:d,:e].nilfil(4) #=> [:a, :b, :b, :d, :e]
class Array
def nilfil(size)
me = self.dup
me[size - 1] = me[size - 1]
me
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment