Skip to content

Instantly share code, notes, and snippets.

@Sinjo
Last active December 20, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sinjo/6125035 to your computer and use it in GitHub Desktop.
Save Sinjo/6125035 to your computer and use it in GitHub Desktop.
JRuby 1.7.4 bug in --2.0 mode JRuby returns an Enumerator. This was the 1.9.3 behaviour, but in 2.0.0 MRI changed to returning an array.
#!/usr/bin/env ruby
lines = ARGV.flat_map { |file_name| File.open(file_name, 'r:bom|utf-8') { |file| file.read.lines } }
p lines
p lines.first
In MRI 2.0.0-p247:
sinjo@widdershins:~/projects/jruby-file-encoding$ rvm use 2.0.0
Using /home/sinjo/.rvm/gems/ruby-2.0.0-p247
sinjo@widdershins:~/projects/jruby-file-encoding$ ./demo input_file.txt
["first line\r\n", "second line\r\n", "third line"]
"first line\r\n"
-----
In JRuby 1.7.4 with JRUBY_OPTS=--2.0:
sinjo@widdershins:~/projects/jruby-file-encoding$ rvm use jruby
Using /home/sinjo/.rvm/gems/jruby-1.7.4
sinjo@widdershins:~/projects/jruby-file-encoding$ ./demo input_file.txt
[#<Enumerator: "first line\r\nsecond line\r\nthird line":lines>]
#<Enumerator: "first line\r\nsecond line\r\nthird line":lines>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment