I’m surprised that not many people knew about ‘each_byte()’. Maybe it’s
a
problem with Ruby docs? Or maybe it is just counter-intuitive - I would
expect
each() iterate over bytes, and provide each_lines() to iterate over
lines instead.
each_bytes is not a good way to do this, btw. It will not remain
compatibile with Ruby 2.0. And using enumerator is a pretty heavy
solution. Then there’s this…
require ‘facet/string/chars’
Source code for chars.rb:
class String
# Returns an array of characters.
#
# "abc".chars #=> ["a","b","c"]
#
def chars
self.split(//)
end