LeftPad in Ruby
def leftPad(inputStr, paddedLength, ch='.')if ch.length > 1raise "bad input"endpaddedLength = paddedLength - inputStr.lengthif paddedLength < 0return inputStrendreturn ch * paddedLength + inputStrendputs leftPad '1', 1puts leftPad '2', 2puts leftPad '3', 3puts leftPad'4', 4puts leftPad '5', 5puts leftPad 'hello', 7puts leftPad "foo", 6puts leftPad "foo", 3puts leftPad "foobar", 3puts leftPad "foo", 6, "?"