Class: String
Instance Method Summary collapse
-
#center(width, str = " ") ⇒ Object
from rubinius.
- #empty? ⇒ Boolean
- #inspect ⇒ Object
-
#justify_string(width, str, justify) ⇒ Object
justify left = -1, center = 0, right = 1.
-
#ljust(width, str = " ") ⇒ Object
from rubinius.
-
#rjust(width, str = " ") ⇒ Object
from rubinius.
- #to_s ⇒ Object (also: #to_str)
Methods included from Comparable
#<, #<=, #==, #>, #>=, #between?
Instance Method Details
#center(width, str = " ") ⇒ Object
from rubinius
620 621 622 |
# File 'lib/builtinME.rb', line 620 def center(width, str=" ") justify_string(width, str, 0) end |
#empty? ⇒ Boolean
585 586 587 |
# File 'lib/builtinME.rb', line 585 def empty? length == 0 end |
#justify_string(width, str, justify) ⇒ Object
justify left = -1, center = 0, right = 1
595 596 597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/builtinME.rb', line 595 def justify_string(width, str, justify) return self if width <= length pad = width - length out = str.to_str * (pad / str.length) out << str[0, pad - out.length] if out.length < pad # Left justification return self << out if justify == -1 # Right justification return out << self if justify == 1 # and finially center split = (width / 2) - (length / 2) return out.insert(split-((width-length)%2), self) end |
#ljust(width, str = " ") ⇒ Object
from rubinius
615 616 617 |
# File 'lib/builtinME.rb', line 615 def ljust(width, str=" ") justify_string(width, str, -1) end |
#rjust(width, str = " ") ⇒ Object
from rubinius
610 611 612 |
# File 'lib/builtinME.rb', line 610 def rjust(width, str=" ") justify_string(width, str, 1) end |