Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

plugin.rb incompatibility with Ruby 1.9

#2130

railties/lib/commands/plugin.rb uses the method "reject" on a String, but String no longer has this method in Ruby 1.9 (since String is no longer Enumerable).

The attached patch adds a call to String#lines, per the suggestion at: http://eigenclass.org/hiki/Chang...

The error message is of the form: plugin.rb:137:in externals': undefined methodreject' for "":String (NoMethodError)

I've been trying to submit a patch through git for the past two days, but can't even get rails test to work out of the box. Relevant threads are at: http://groups.google.com/group/r...

Reported by Jeff Schwab · March 4th, 2009 @ 08:11 PM

State: committed
Milestone: 2.x
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. Matt Jones
    Matt Jones
    • Tag changed from patch to patch, ruby1.9

    This patch still needs some work - note that String#lines is not defined for RUBY_VERSION < 1.9. Given the current speed of the migration effort, Ruby 1.8 support is needed. I'd recommend that you revise the patch in the spirit of line 904 of plugin.rb:

    
        @urls_to_fetch = RUBY_VERSION >= '1.9' ? urls_to_fetch.lines : urls_to_fetch.to_a
    

    ..which will work correctly on both 1.9 and 1.8.

    Either that, or you could use an approach like this:

    
    lines = str.send(str.respond_to?(:lines) ? :lines : :to_s).to_a
    

    (from this blog post )

    March 4th, 2009 @ 08:52 PM

  2. Jeff Schwab
    Jeff Schwab

    Thanks for the gentle treatment of my rookie mistake. An updated patch is attached.

    In other codebases, I would include a comment, explaining what I did and why, and referring to this bug report. I see that there are no other such comments in the file, so I guess they only go in the version control logs. Here is a "starter" log entry:

    Ruby 1.8 strings are Enumerable, but do not support :lines. In Ruby 1.9, the situation is reversed.

    March 4th, 2009 @ 09:48 PM

  3. Jeff Schwab
  4. Pratik
    Pratik
    • Assigned user set to Jeremy Kemper

    March 9th, 2009 @ 12:58 PM

  5. Repository
    Repository
    • State changed from new to committed

    (from [e609d83f1a7f49bf8a9549c480a67ee045950336]) Fixed an incompatibility with Ruby 1.9.

    Ruby 1.8 strings are Enumerable, but there is no String#lines method. In Ruby 1.9, the situation is reversed. To work around this disparity, the RailsEnvironment#externals method now explicitly checks whether a String responds_to? :lines.

    [#2130 plugin.rb incompatibility with Ruby 1.9 state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    March 10th, 2009 @ 06:58 PM