This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Processing a String One Character at a Time
CodeExpectedActual
'foobar'.each_byte { |x| puts "#{x} = #{x.chr}" }
102 = f
111 = o
111 = o
98 = b
97 = a
114 = r
102 = f
111 = o
111 = o
98 = b
97 = a
114 = r
'foobar'.scan( /./ ) { |c| puts c }
f
o
o
b
a
r
f
o
o
b
a
r
"foo\nbar".each { |x| puts x }
foo
bar
foo
bar
french = "\xc3\xa7a va"
french.scan(/./) { |c| puts c }

a

v
a

a
 
v
a
french.scan(/./u) { |c| puts c }
ç
a

v
a
ç
a
 
v
a
$KCODE = 'u'
french.scan(/./) { |c| puts c }
ç
a

v
a
ç
a
 
v
a