To get the last n characters from a string, I assumed you could use
n
ending = string[-n..-1]
but if the string is less than
Well, the easiest workaround I can think of is:
ending = str[-n..-1] || str
(EDIT: The or operator has lower precedence than assignment, so be sure to use || instead.)
or
||