Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
$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}" end end # ===== 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"
This paste will be private.
From the Design Piracy series on my blog: