Skip to content

Instantly share code, notes, and snippets.

@Githerdone
Last active December 16, 2015 16:29
Show Gist options
  • Save Githerdone/5463102 to your computer and use it in GitHub Desktop.
Save Githerdone/5463102 to your computer and use it in GitHub Desktop.
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