Created
January 5, 2017 09:48
-
-
Save kminiatures/1539a929072057324d90c956d8fe4734 to your computer and use it in GitHub Desktop.
幅の広い文字がある場合の ljust である ljust_w を String に追加する...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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