Created
September 7, 2012 23:05
-
-
Save emberlzhang/3670546 to your computer and use it in GitHub Desktop.
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
class Array | |
#changes the array | |
def pad!(min_size, value = nil) | |
if min_size <= self.length | |
return self.clone | |
elsif min_size > self.length | |
(min_size - self.length).times do | |
self << value | |
end | |
return self.clone | |
end | |
end | |
#keeps original array the same | |
def pad(min_size, value = nil) | |
result = [] | |
result << self.clone | |
if min_size <= self.length | |
return result | |
elsif min_size > self.length | |
(min_size - self.length).times do | |
result << value | |
end | |
return result | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment