Skip to content

Instantly share code, notes, and snippets.

@Vanderln
Created March 1, 2013 17:22
Show Gist options
  • Save Vanderln/5066235 to your computer and use it in GitHub Desktop.
Save Vanderln/5066235 to your computer and use it in GitHub Desktop.
Socrates Array padding problem
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