From: "Thomas Søndergaard" Date: 2002-08-11T22:47:56+09:00 Subject: Re: empty file returns nil not empty string? Sure - here's a test case: require 'test/unit' class TestFileRead < Test::Unit::TestCase def test_read_empty `touch empty.txt` assert_equal(0, File.size("empty.txt")) File.open("empty.txt") { |f| assert_equal("", f.read) assert_equal(nil, f.read) } end end Here's the output =========================== $ /C/ruby167/bin/ruby readtest.rb Loaded suite readtest Started... .. Finished in 0.13 seconds. 1 runs, 3 assertions, 0 failures, 0 errors =========================== $ /C/ruby172/bin/ruby readtest.rb c:/ruby172/lib/ruby/site_ruby/1.7/test/unit/error.rb:35: warning: escaped terminator '"' inside string interpolation Loaded suite readtest Started... .. Failure occurred in test_read_empty(TestFileRead) [readtest.rb:12]: Expected <> but was Finished in 0.02 seconds. 1 runs, 2 assertions, 1 failures, 0 errors =========================== Cheers, Thomas > >>>>> "T" == =?iso-8859-1?Q?Thomas S=F8ndergaard?= writes: > > T> In ruby-1.6.7 reading an empty file returns an empty string before returning > T> nil. 1.7.2 doesn't do that - why? > > Can you give an example ? > > pigeon% ls -al aa > -rw-r--r-- 1 ts ts 0 Aug 11 15:06 aa > pigeon% > > pigeon% ruby -ve 'a = File.open("aa"); while b = a.gets; p b; end' > ruby 1.6.7 (2002-03-01) [i686-linux] > pigeon% > > > Guy Decoux >