class String
def rjustb(width, padding = ' ')
rjust(width-(bytesize-size), padding)
end
def ljustb(width, padding = ' ')
ljust(width-(bytesize-size), padding)
end
end
def disp(strs, title="")
puts (" %s "%title).center(40, '*') if title
puts
strs.each{|str| yield str}
puts
end
disp(%w{1234}, "【 rjustとの動作比較 】") do |str|
p "|rjust |" << str.rjust(10)
p "|rjustb|" << str.rjustb(10)
end
disp(%w{1234}, "【 ljustとの動作比較 】") do |str|
p "|ljust |" << str.ljust(10)
p "|ljustb|" << str.ljustb(10)
end
disp(%w{1234 1234 1234 1234 1234}, "【 rjustbの動作 】") do |str|
p str.rjustb(10)
end
disp(%w{1234 1234 1234 1234 1234}, "【 ljustbの動作 】") do |str|
p str.ljustb(10)
end