method
justify
v2.2.1 -
Show latest stable
-
0 notes -
Class: ActiveSupport::Multibyte::Chars
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
justify(integer, way, padstr=' ')
protected
Hide source
# File activesupport/lib/active_support/multibyte/chars.rb, line 646 def justify(integer, way, padstr=' ') #:nodoc: raise ArgumentError, "zero width padding" if padstr.length == 0 padsize = integer - size padsize = padsize > 0 ? padsize : 0 case way when :right result = @wrapped_string.dup.insert(0, self.class.padding(padsize, padstr)) when :left result = @wrapped_string.dup.insert(-1, self.class.padding(padsize, padstr)) when :center lpad = self.class.padding((padsize / 2.0).floor, padstr) rpad = self.class.padding((padsize / 2.0).ceil, padstr) result = @wrapped_string.dup.insert(0, lpad).insert(-1, rpad) end chars(result) end