I'm new to Ruby and am trying to work something out which is confusing me. While writing a simple parser, I found that comparing a char with a ==
would produce a different result than comparing it with a case
expression:
File.open('Quote.txt') do |f|
f.chars.each do |c|
puts c == '"' ? 'Quote' : 'Err'
puts case c
when '"' then 'QuoteCase'
else 'ErrCase'
end
p c == '"', c === '"', c
end
end
Assuming Quote.txt
is a 1-byte file containing a single quote character (0x22
), this produces:
Quote
ErrCase
true
true
"\""
I'm assuming I've done something wrong, but I can't figure out what it is. Can anyone help?
This is in Ruby 1.9.2, by the way.