diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/iterators.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/iterators.rb | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/iterators.rb b/activesupport/lib/active_support/core_ext/string/iterators.rb index fe17d140ca..472de7bc24 100644 --- a/activesupport/lib/active_support/core_ext/string/iterators.rb +++ b/activesupport/lib/active_support/core_ext/string/iterators.rb @@ -1,22 +1,13 @@ -require 'strscan' +unless '1.9'.respond_to?(:each_char) + autoload :StringScanner, 'strscan' unless defined? :StringScanner -module ActiveSupport #:nodoc: - module CoreExtensions #:nodoc: - module String #:nodoc: - # Custom string iterators - module Iterators - def self.append_features(base) - super unless '1.9'.respond_to?(:each_char) - end - - # Yields a single-character string for each character in the string. - # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately. - def each_char - scanner, char = StringScanner.new(self), /./mu - while c = scanner.scan(char) - yield c - end - end + class String + # Yields a single-character string for each character in the string. + # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately. + def each_char + scanner, char = StringScanner.new(self), /./mu + while c = scanner.scan(char) + yield c end end end |