Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.instance_methods different for jRuby inside Rails #4733

Closed
straydogstudio opened this issue Aug 3, 2017 · 5 comments
Closed

Array.instance_methods different for jRuby inside Rails #4733

straydogstudio opened this issue Aug 3, 2017 · 5 comments

Comments

@straydogstudio
Copy link

straydogstudio commented Aug 3, 2017

Submitted this to Rails, they declined the issue as being a jRuby problem. Resubmitted here should you wish to address.

Description

Needed each_with_index in Array.instance_methods. Found it was missing (along with several other methods) within Rails when using jRuby 9.

Steps to reproduce

Using Docker:

docker run -it --rm --name arraytest jruby /bin/bash
# gem install rails
# gem install listen
# rails new arraytest -O
# cd arraytest
# echo "gem 'listen', group: :development" >> Gemfile
# bundle exec rails c
irb > Array.instance_methods.select {|m| m =~ /each/}
irb > exit
# irb
irb > Array.instance_methods.select {|m| m =~ /each/}

To check MRI, replace the jruby image with ruby.

Expected behavior

Whether in our out of Rails, using MRI or jRuby, Array.instance_methods should return the same thing.

Actual behavior

When using jRuby 9 inside Rails 5.0, Array.instance_methods doesn't have each_cons, each_entry, each_with_index, each_with_object, as well as several other methods. They are present with MRI. Outside Rails they are present in jRuby.

This is the difference, which may contain some artifacts due to other required gem changes between MRI and jRuby:

 [:all?, :byebug, :chunk, :chunk_while, :collect_concat, :detect, :each_cons, :each_entry, :each_with_index, :each_with_object, :entries, :exclude?, :find, :find_all, :flat_map, :grep, :grep_v, :group_by, :index_by, :inject, :lazy, :many?, :max_by, :member?, :min_by, :minmax, :minmax_by, :none?, :one?, :partition, :pluck, :reduce, :singleton_method, :slice_after, :slice_before, :slice_when, :sort_by, :sum, :to_h, :to_ruby, :to_set]

System configuration

Rails version: 5.0.3 or 5.1.1

Ruby version: jRuby 9.1.10.0, MRI 2.4.1p111

Temporary fix

In config/application.rb, right before the Bundler.require* statement, add:

Array.include Enumerable

Other

Found because the Axlsx gem uses Array.instance_methods to delegate methods. When used inside Rails 5.0 with jRuby it fails. See randym/axlsx#533

Submitted and declined as a Rails issue: rails/rails#29329

@enebo
Copy link
Member

enebo commented Aug 3, 2017

@straydogstudio by chance do you know if this behavior is the same with MRI 2.3.x? JRuby 9.1.x is not compatible with 2.4 (although we are working on that support) and it would be good to know if this a 2.3- or a 2.4 issue.

@straydogstudio
Copy link
Author

@enebo I do not know. But I'll try to check on that in the next few days.

@bmulvihill
Copy link
Contributor

bmulvihill commented Aug 3, 2017

I opened related issue here: #4723 @enebo @straydogstudio

@enebo
Copy link
Member

enebo commented Aug 3, 2017

@bmulvihill ah great..I missed that. I could see prepend being responsible as it has caused other oddities since we impld it.

@headius headius added this to the JRuby 9.2.0.0 milestone Aug 7, 2017
@enebo enebo modified the milestones: JRuby 9.1.13.0, JRuby 9.2.0.0 Aug 16, 2017
@headius
Copy link
Member

headius commented Aug 24, 2017

I have not confirmed it but this should be fixed by the fixes for #4723. Please verify.

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

No branches or pull requests

4 participants