Project

General

Profile

Bug #4437 ยป getc_bug.rb

Sample program that shows the error. - bobjalex (Bob Alexander), 02/24/2011 12:08 PM

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

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

    
5
# Create a Hash with 'x' as a key.

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

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

9
# characters.

10
p 'h["x"] =>', h["x"]
11
p 'h[?x] =>', h[?x]
12

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

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

15
puts
16
p 'x =>', x
17
p 'h[x] =>', h[x]