Last active
December 16, 2015 16:29
-
-
Save Githerdone/5463102 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Array | |
def pad!(min_size, value = nil) | |
if self.count >= min_size | |
return self | |
else | |
size_is = min_size - self.count | |
count = 0 | |
while count < size_is | |
self << value | |
count += 1 | |
end | |
return self | |
end | |
end | |
def pad(min_size, value = nil) | |
if self.count >= min_size | |
return new_array = self.clone | |
else | |
new_array = self.clone | |
size_is = min_size - self.count | |
count = 0 | |
while count < size_is | |
new_array << value | |
count += 1 | |
end | |
return new_array | |
end | |
end | |
end | |
[1,2,3].pad!(5, "apple") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment