Skip to content

Instantly share code, notes, and snippets.

@dlozano
Last active December 15, 2015 18:09
Show Gist options
  • Select an option

  • Save dlozano/5302054 to your computer and use it in GitHub Desktop.

Select an option

Save dlozano/5302054 to your computer and use it in GitHub Desktop.
WTF RUBY 1.8 !!!!!!!
def ljust(str, required_length, padstr = ' ')
just(str, true, padstr)
end
def rjust(str, required_length, padstr = ' ')
just(str, false, padstr)
end
def just(str, required_length, left = true, padstr = ' ')
amount = [0, (required_length - str.mb_chars.length)].max
result = [str, padstr * amount]
left ? result.join : result.reverse.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment