Module: Hirb::String

Extended by:
String
Included in:
String
Defined in:
lib/hirb/string.rb

Overview

Provides string helpers to deal with UTF-8 and ruby 1.8.x

Instance Method Summary collapse

Instance Method Details

#ljust(string, desired_length) ⇒ Object



11
12
13
14
# File 'lib/hirb/string.rb', line 11

def ljust(string, desired_length)
  leftover = desired_length - size(string)
  leftover > 0 ? string + " " * leftover : string
end

#rjust(string, desired_length) ⇒ Object



16
17
18
19
# File 'lib/hirb/string.rb', line 16

def rjust(string, desired_length)
  leftover = desired_length - size(string)
  leftover > 0 ? " " * leftover + string : string
end

#size(string) ⇒ Object



7
8
9
# File 'lib/hirb/string.rb', line 7

def size(string)
  string.scan(/./).length
end

#slice(*args) ⇒ Object



21
22
23
# File 'lib/hirb/string.rb', line 21

def slice(string, start, finish)
  string.scan(/./).slice(start, finish).join('')
end