Created
August 10, 2014 03:04
-
-
Save libkazz/75a032e89c016ffcde0a to your computer and use it in GitHub Desktop.
fill with nil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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