LeftPad in Ruby

Press + to interact
def leftPad(inputStr, paddedLength, ch='.')
if ch.length > 1
raise "bad input"
end
paddedLength = paddedLength - inputStr.length
if paddedLength < 0
return inputStr
end
return ch * paddedLength + inputStr
end
puts leftPad '1', 1
puts leftPad '2', 2
puts leftPad '3', 3
puts leftPad'4', 4
puts leftPad '5', 5
puts leftPad 'hello', 7
puts leftPad "foo", 6
puts leftPad "foo", 3
puts leftPad "foobar", 3
puts leftPad "foo", 6, "?"