Here's what I have now and it is somewhat working:
def padding(a, b, c=nil)
until a[b-1]
a << c
end
end
This is when it works:
a=[1,2,3]
padding(a,10,"YES")
=>[1, 2, 3, "YES", "YES", "YES", "YES", "YES", "YES", "YES"]
a[1,2,3]
padding(a,10,1)
=>[1, 2, 3, 1, 1, 1, 1, 1, 1, 1]
But it crashes when I do not enter a value for "c"
a=[1,2,3]
padding(a,10)
Killed
How should I append this to avoid a crash? Additionally, how would you suggest changing this method to use it as follows:
[1,2,3].padding(10)
=>[1,2,3,nil,nil,nil,nil,nil,nil,nil]
[1,2,3].padding(10, "YES")
=>[1, 2, 3, "YES", "YES", "YES", "YES", "YES", "YES", "YES"]
I've seen other padding methods on SO, but they don't seem to be working as intended by the authors. So, I decided to give making my own a shot.