This project is archived and is in readonly mode.
script/server make an error in Ruby 1.9 because of defined? method's change
Reported by Masayoshi Takahashi | October 5th, 2008 @ 05:00 PM
The behavior of defined? method is changed in Ruby 1.9.
$ ruby -ve 'require "rubygems";p defined?(Gem::RubyGemsVersion);x=Gem::RubyGemsVersion;p defined?(Gem::RubyGemsVersion)' ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0] "constant" "constant"
$ ~/ruby190_20080928/bin/ruby -ve 'require "rubygems";p defined?(Gem::RubyGemsVersion);x=Gem::RubyGemsVersion;p defined?(Gem::RubyGemsVersion)' ruby 1.9.0 (2008-10-02 revision 15736) [i386-darwin9.5.0] nil "constant"
So, current rails is broken in Ruby 1.9.0.
$ ~/ruby190_20080928/bin/ruby -v script/server ruby 1.9.0
(2008-10-02 revision 15736) [i386-darwin9.5.0]
/Users/maki/tmp/test3/config/boot.rb:86:in load_rubygems':
undefined method
>=' for nil:NilClass (NoMethodError)
from /Users/maki/tmp/test3/config/boot.rb:52:in `load_initializer'
from /Users/maki/tmp/test3/config/boot.rb:38:in `run'
from /Users/maki/tmp/test3/config/boot.rb:11:in `boot!'
from /Users/maki/tmp/test3/config/boot.rb:109:in `<top (required)>'
from script/server:2:in `require'
from script/server:2:in `<main>'
This change of defined? seems to be specification of Ruby 1.9. In Changelog, Matz wrote:
Mon Aug 25 23:01:17 2008 Yukihiro Matsumoto matz@ruby-lang.org
* compile.c (defined_expr): default defined? should return
"expression" without evaluating the expression. [ruby-dev:35967]
I wrote a patch for the problem.
Thanks in advance,
Comments and changes to this ticket
-
Carlos Paramio November 4th, 2008 @ 04:06 PM
- Tag changed from ruby1.9 to 2.2, railties, ruby1.9
I can reproduce this. I think it is more that rubygems are automatically loaded by Ruby 1.9, but only the first time a gem (or rubygem itself) is used. So when Ruby 1.9 evaluates "defined? Gem::RubyGemsVersion" the first time, it returns nil, even when the Gem module is already available. Ex:
$ irb1.9
defined? Gem::RubyGemsVersion => nil Gem::RubyGemsVersion => "1.2.0.1824" defined? Gem::RubyGemsVersion => "constant"
Here is a (possibly) simpler patch to make it work with both Ruby stable and unstable versions:
--- environments/boot.rb.old 2008-11-04 17:00:31.000000000 +0100 +++ environments/boot.rb 2008-11-04 17:02:44.000000000 +0100 70c70
< Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
Gem::RubyGemsVersion rescue nil
-
Carlos Paramio November 4th, 2008 @ 04:13 PM
Ooops. Sorry, I forgot the <code> tags.
The example:
$ irb1.9 >> defined? Gem::RubyGemsVersion => nil >> Gem::RubyGemsVersion => "1.2.0.1824" >> defined? Gem::RubyGemsVersion => "constant"
The patch:
--- environments/boot.rb.old 2008-11-04 17:00:31.000000000 +0100 +++ environments/boot.rb 2008-11-04 17:02:44.000000000 +0100 70c70 < Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion --- > Gem::RubyGemsVersion rescue nil
-
Carlos Paramio November 4th, 2008 @ 07:34 PM
- Tag changed from 2.2, railties, ruby1.9 to 2.2, patch, railties, ruby1.9, ruby19
I used "git diff" to create the patch, but checking the contributions guide, it seems that the preferred format is the output of "git format-patch", so I've included the new patch file that substitutes the first one, with extension ".diff" as it appears at the guide. My apologize for any inconvenience.
-
Carlos Paramio November 19th, 2008 @ 05:14 PM
- Assigned user set to Jeremy Kemper
Michael Koziarski said at the rails-core mailing list:
Jeremy's been keeping an eye on our 1.9 compatibility, and he's the best one to pipe up with a reply. However my understanding is that several 1.9 changes have broken 2.2 support (test related assertions f.ex) and we'll likely be holding off till 2.3 before we ship a '1.9 friendly' release.
Jeremy, can you confirm this please? Thanks!
-
Jeremy Kemper November 19th, 2008 @ 05:54 PM
- Milestone cleared.
- State changed from new to committed
Rails 2.2 is Ruby 1.9-friendly also, with some caveats, such as using the test-unit gem instead of minitest.
8412200f90c239cbf12bb32b5246d0104306f6c2
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 5937 ActiveResource does not use XMLFormat to encode new elements for decoding a Resource the format's decode method is use...