Skip to content

Instantly share code, notes, and snippets.

@kminiatures
Created January 5, 2017 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kminiatures/1539a929072057324d90c956d8fe4734 to your computer and use it in GitHub Desktop.
Save kminiatures/1539a929072057324d90c956d8fe4734 to your computer and use it in GitHub Desktop.
幅の広い文字がある場合の ljust である ljust_w を String に追加する...
class String
def length_w
alpha = self.scan /[a-zA-Z0-9 ]/
double = self.length - alpha.length
double * 2 + alpha.length
end
def ljust_w(width)
len = width - (self.length_w)
len = 0 if len < 0
"#{self}#{" "*(len)}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment