Sha256: 82093bc5e714095ec0df0027b7cf1640ba652c6b453d994acb75b5c6a0bb0fdd

Contents?: true

Size: 525 Bytes

Versions: 2

Compression:

Stored size: 525 Bytes

Contents

class String
  def print_length
    self.each_char.map{|c| c.bytesize == 1 ? 1 : 2}.reduce(0, &:+)
  end
  
  def rpad(length, padding = " ")
    self + (padding * (length - self.print_length))
  end

  def lpad(length, padding = " ")
    (padding * (length - self.print_length)) + self
  end

  def padding(length, type = nil)
    begin # auto decection code.
      raise ArgumentError if type == :string
      Float(self)
      self.lpad(length, "0")
    rescue ArgumentError
      self.rpad(length, " ")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pretty_hash-0.0.2 lib/pretty_hash/string.rb
pretty_hash-0.0.1 lib/pretty_hash/string.rb