Created
March 1, 2013 17:22
-
-
Save Vanderln/5066235 to your computer and use it in GitHub Desktop.
Socrates Array padding problem
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 min_size <= self.length | |
self | |
else | |
(min_size - self.length).times{|x| self.push(value)} | |
self | |
end | |
end | |
def pad(min_size, value = nil) | |
if min_size <= self.length | |
self.clone | |
else | |
(min_size - self.length).times{|x| self.push(value)} | |
self.clone | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment