0
File.open("/tmp/test") do |file|
  file.each_line("e") {|line|
    puts "Got #{ line.dump }"
  }
end

在 irb 中返回“IOError:关闭的流”。但是如果它保存在文件'test.rb'中,ruby test.rb- 工作正常。Ruby 版本:ruby-2.0.0-p247、ruby-2.1.0-preview1、Ubuntu、Mac OS。我做错了什么?

user:ads user$ echo "a\nb\nc" > /tmp/test
user:ads user$ irb
2.1.0-preview1 :001 > File.open("/tmp/test") { |file| file.each_line { |line| puts "Got #{ line.dump }" } }
Got "a\\nb\\nc\n"
IOError: closed stream
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/formatter.rb:199:in `directory?'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/formatter.rb:199:in `awesome_file'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/formatter.rb:26:in `format'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/inspector.rb:137:in `unnested'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/inspector.rb:104:in `awesome'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/kernel.rb:10:in `ai'
    from /Users/user/.rvm/gems/ruby-2.1.0-preview1/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/kernel.rb:20:in `ap'
    from /Users/user/.irbrc:7:in `output_value'
    from /Users/user/.rvm/rubies/ruby-2.1.0-preview1/bin/irb:15:in `<main>'
4

1 回答 1

0

https://github.com/michaeldv/awesome_print/pull/141中的可能修复

- ls = File.directory?(f) ? `ls -adlF #{f.path.shellescape}` : `ls -alF #{f.path.shellescape}`
+ ls = `ls -adlF #{f.path.shellescape}`
于 2013-11-11T10:04:45.773 回答