Skip to content

In Ruby 2.0, String#lines returns an Array, rather than an Enumerator#945

Merged
headius merged 1 commit intojruby:masterfrom
Sinjo:fix_string_lines_2_0
Aug 4, 2013
Merged

In Ruby 2.0, String#lines returns an Array, rather than an Enumerator#945
headius merged 1 commit intojruby:masterfrom
Sinjo:fix_string_lines_2_0

Conversation

@Sinjo
Copy link
Contributor

@Sinjo Sinjo commented Aug 4, 2013

Ruby 2.0 has changed the return type of String#lines to Array, from Enumerator. The difference in behaviour between MRI 2.0.0 and JRuby 1.7.4 with the --2.0 argument supplied is:

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>

Output taken from this gist

headius added a commit that referenced this pull request Aug 4, 2013
In Ruby 2.0, String#lines returns an Array, rather than an Enumerator
@headius headius merged commit 436b5f7 into jruby:master Aug 4, 2013
@headius
Copy link
Member

headius commented Aug 4, 2013

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants