Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_figlet/parser.rb,
lib/ruby_figlet/interface.rb

Overview

Add some useful methods for String class:

  • String#to_utf8 forces utf8 encoding

  • String#delete_at returns a new string with a certain index of a character

deleted.

  • String#delete_at! is the self mutating equivilant.

Instance Method Summary collapse

Instance Method Details

#delete_at(n) ⇒ Object



19
20
21
# File 'lib/ruby_figlet/parser.rb', line 19

def delete_at n
  dup.delete_at! n
end

#delete_at!(n) ⇒ Object



14
15
16
17
# File 'lib/ruby_figlet/parser.rb', line 14

def delete_at! n
  slice! n
  self
end

#eachObject



2
3
4
5
6
7
8
# File 'lib/ruby_figlet/interface.rb', line 2

def each
  i = 0
  while i < length
    yield self[i]
    i += 1
  end
end

#to_utf8Object



7
8
9
10
11
12
# File 'lib/ruby_figlet/parser.rb', line 7

def to_utf8
  str = force_encoding 'UTF-8'
  return str if str.valid_encoding?
  str = str.force_encoding 'BINARY'
  str.encode 'UTF-8', :invalid => :replace, :undef => :replace
end