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 | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/iterators.rb b/activesupport/lib/active_support/core_ext/string/iterators.rb new file mode 100644 index 0000000000..73114d9d5f --- /dev/null +++ b/activesupport/lib/active_support/core_ext/string/iterators.rb @@ -0,0 +1,17 @@ +require 'strscan' + +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module String #:nodoc: + # Custom string iterators + module Iterators + # 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 + loop { yield(scanner.scan(char) || break) } + end + end + end + end +end |