File: active_support/core_ext/string/iterators.rb

Overview
Module Structure
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: ActiveSupport#3
  module: CoreExtensions#4
  module: String#5
  module: Iterators#7
has properties
module method: append_features / 1 #8
method: each_char #14

Code

   1  require 'strscan'
   2 
   3  module ActiveSupport #:nodoc:
   4    module CoreExtensions #:nodoc:
   5      module String #:nodoc:
   6        # Custom string iterators
   7        module Iterators
   8          def self.append_features(base)
   9            super unless '1.9'.respond_to?(:each_char)
  10          end
  11 
  12          # Yields a single-character string for each character in the string.
  13          # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
  14          def each_char
  15            scanner, char = StringScanner.new(self), /./mu
  16            while c = scanner.scan(char)
  17              yield c
  18            end
  19          end
  20        end
  21      end
  22    end
  23  end