class String
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.
Public Instance Methods
delete_at(n)
click to toggle source
# File lib/ruby_figlet/parser.rb, line 19 def delete_at n dup.delete_at! n end
delete_at!(n)
click to toggle source
# File lib/ruby_figlet/parser.rb, line 14 def delete_at! n slice! n self end
each() { |self| ... }
click to toggle source
# File lib/ruby_figlet/interface.rb, line 2 def each i = 0 while i < length yield self[i] i += 1 end end
to_utf8()
click to toggle source
# 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