$filename='test.dat'['a','aa'].each do |data|
puts "=== Trying with data = '#{data}'"# Write data
File.open($filename,'w'){|io| io.write(data)}# Read data without calling io.eof?
File.open($filename,'r')do |io|
read_data = io.read(1000)
puts "Data read without calling io.eof? = #{read_data.inspect}"end# Read data with calling io.eof?
File.open($filename,'r')do |io|
io.eof?
read_data = io.read(1000)
puts "Data read with calling io.eof? = #{read_data.inspect}"endend# ===== ACTUAL OUTPUT
## === Trying with data = 'a'
# Data read without calling io.eof? = "a"
# Data read with calling io.eof? = nil
# === Trying with data = 'aa'
# Data read without calling io.eof? = "aa"
# Data read with calling io.eof? = "aa"
## ===== EXPECTED OUTPUT
## === Trying with data = 'a'
# Data read without calling io.eof? = "a"
# Data read with calling io.eof? = "a"
# === Trying with data = 'aa'
# Data read without calling io.eof? = "aa"
# Data read with calling io.eof? = "aa"