Skip to content

Commit

Permalink
refactor SuperPad
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 30, 2015
1 parent 30011f7 commit bc5d63f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions library/types/src/modules/String.rb
Expand Up @@ -358,14 +358,15 @@ def Repeat(text, number)
# @param [Symbol] alignment alignment to use, either `left or `right
# @return padded text
def SuperPad(text, length, padding, alignment)
text = "" if text.nil?
text ||= ""
return text if length.nil? || text.size >= length || padding.nil?

pad = Repeat(padding, Ops.subtract(length, Builtins.size(text)))
pad = padding * (length - text.size)

if alignment == :right
return Ops.add(pad, text)
return pad + text
else
return Ops.add(text, pad)
return text + pad
end
end

Expand Down

0 comments on commit bc5d63f

Please sign in to comment.