Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Array() does not coerce according to MRI 1.9 logic #1962
The following code should work:
class Foo def method_missing(name, *args)  end end fail unless  == Array(Foo.new)
The existing logic (possibly from 1.8) does not follow the method_missing path. If there's no to_ary or to_a, the object is just wrapped in an array.
This is the cause of the first bunch of errors in this Travis CI job (thanks @rkh): https://travis-ci.org/travis-ci/travis-yaml/builds/34826144
referenced this issue
Sep 10, 2014
Reverted in jruby-1_7 only because this was causing issues with Rails 4. I also noticed we are not properly handling:
class Foo private def to_ary  end def to_a  end end p Array(Foo.new)
This example is probably not the Rails 4 issue but it is in the general pool of differences during coercion we are not properly observing.
This simplest reproducer for the Rails 4 issue I can come up with is this:
class Foo private def to_ary; end def to_a; end def method_missing(method, *args) super end end Array(Foo.new)
Running this results in: