Forum: Ruby 1.9 bug?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Roger P. (Guest)
on 2008-10-12 06:44
here's a function


      def rubygems_version
         Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
       end

1.8.6
irb(main):005:0* rubygems_version
=> "1.3.0"

1.9

irb(main):001:0>       def rubygems_version
irb(main):002:1>         Gem::RubyGemsVersion if defined?
Gem::RubyGemsVersion
irb(main):003:1>       end
=> nil

hmm.


I guess it's because of the way that 1.9 'auto integrates' gems?

  irb19
>> defined? Gem::RubyGemsVersion
=> nil
>> require 'rubygems'
=> false
>> defined? Gem::RubyGemsVersion
=> nil
>> Gem::RubyGemsVersion
=> "1.3.0"
>> defined? Gem::RubyGemsVersion
=> "constant"

After this point the rubygems_version method works in 1.9


-=R
Roger P. (Guest)
on 2008-10-12 06:48
Another 1.9 gems difference [?]

/Users/rogerpack/dev/ruby_19_installed/lib/ruby/gems/1.9.0/gems/rails-2.1.0/lib/rails/plugin/locator.rb:81:in
`map': private method `specification' called for
#<Rails::GemDependency:0x139ba24> (NoMethodError)

doesn't happen in 1.8
(both with gems v 1.3)

Thanks.
-=R
David P. (Guest)
on 2008-10-13 10:33
(Received via mailing list)
> => "1.3.0"
>>> defined? Gem::RubyGemsVersion
> => "constant"
>
> After this point the rubygems_version method works in 1.9


I've seen this too; it's especially annoying as it stops rails from
booting out of the box.

The fix is easy though. In boot.rb, change:
  unless rubygems_version >= '0.9.4'
into:
  unless (rubygems_version || Gem::RubyGemsVersion) >= '0.9.4'

I'd be very interested in hearing the explanation for this weird
behaviour!
Eric H. (Guest)
on 2008-10-14 10:43
(Received via mailing list)
On Oct 11, 2008, at 19:41 PM, Roger P. wrote:
>
>
> => "1.3.0"
>>> defined? Gem::RubyGemsVersion
> => "constant"
>
> After this point the rubygems_version method works in 1.9

Something seems to be preventing defined?'s const_missing from being
handled properly.  I'll look into it.
This topic is locked and can not be replied to.