Skip to content

Array.instance_methods different for jRuby inside Rails #4733

@straydogstudio

Description

@straydogstudio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions