Project

General

Profile

Actions

Bug #4437

closed

Hash does not match character read from file via IO#getc

Added by bobjalex (Bob Alexander) almost 14 years ago. Updated about 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
Backport:
[ruby-core:<unknown>]

Description

Run this little program, and observe that the single-character read from a file does not match a hash key as it should.

===========================================

Create a file with the single character 'x', then read it back into var x.

open('x', 'w') {|f| f.write('x')}
x = open('x') {|f| f.getc}

Create a Hash with x as a key.

h = {'x' => 'xx'}

Retrieve the value, to show that the hash (of course) works with ordinary

characters.

p 'h["x"] =>', h["x"]
p 'h[?x] =>', h[?x]

Retrieve the value using the 'x' obtained using getc, showing that the

hash match fails for the same character as retrieved from a file.

puts
p 'x =>', x
p 'h[x] =>', h[x]


Files

getc_bug.rb (516 Bytes) getc_bug.rb Sample program that shows the error. bobjalex (Bob Alexander), 02/24/2011 12:08 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0