Module: ActiveSupport::CoreExtensions::String::Iterators

Included in:
String
Defined in:
lib/active_support/core_ext/string/iterators.rb

Overview

Custom string iterators

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object



8
9
10
# File 'lib/active_support/core_ext/string/iterators.rb', line 8

def self.append_features(base)
  super unless '1.9'.respond_to?(:each_char)
end

Instance Method Details

#each_charObject

Yields a single-character string for each character in the string. When $KCODE = ‘UTF8’, multi-byte characters are yielded appropriately.



14
15
16
17
18
19
# File 'lib/active_support/core_ext/string/iterators.rb', line 14

def each_char
  scanner, char = StringScanner.new(self), /./mu
  while c = scanner.scan(char)
    yield c
  end
end