Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#each_character_with_indexObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/extensions/string.rb', line 10

def each_character_with_index
  self.split("").each_with_index do |chr, index|
    next if !@skip_iteration_index.nil? && @skip_iteration_index >= index

    skip_iteration_index = catch :skip_iteration do
      yield(chr, index) if block_given?
    end

    @skip_iteration_index = skip_iteration_index if skip_iteration_index.kind_of?(Integer)
  end
end

#each_character_with_index_from(from_index) ⇒ Object



4
5
6
7
8
# File 'lib/extensions/string.rb', line 4

def each_character_with_index_from(from_index)
  self.split("")[from_index..-1].each_with_index do |chr, index|
    yield(chr, index + from_index) if block_given?
  end
end