[#9722] Kernel#system broken inside Dir.chdir(&block) if system command doesn't have shell characters — <noreply@...>

Bugs item #7278, was opened at 2006-12-14 13:59

8 messages 2006/12/14

[#9749] System V IPC in standard library? — Steven Jenkins <steven.jenkins@...>

Back in August, I needed a semaphore to serialize access to an external

14 messages 2006/12/19

[#9753] CVS freeze — SASADA Koichi <ko1@...>

Hi,

20 messages 2006/12/20
[#9755] Re: [ruby-dev:30039] CVS freeze — SASADA Koichi <ko1@...> 2006/12/20

Hi,

[#9757] Re: [ruby-dev:30040] Re: CVS freeze — SASADA Koichi <ko1@...> 2006/12/20

Hi,

Delegation and 1.9

From: Francois <fg@...>
Date: 2006-12-24 07:27:39 UTC
List: ruby-core #9782
Hello,

Consider the following two irb sessions, one with 1.8.5 and the other 
with 1.9.0 :

irb(main):001:0> RUBY_VERSION
=> "1.8.5"
irb(main):002:0> require 'delegate'
=> true
irb(main):003:0> class Cookie < DelegateClass(Array)
irb(main):004:1>    attr_reader :name
irb(main):005:1>    def initialize(name)
irb(main):006:2>        @name = name
irb(main):007:2>    end
irb(main):008:1> end
=> nil
irb(main):009:0>
irb(main):010:0* c = Cookie.new('chrismas')
=> nil
irb(main):011:0> c.class
=> Cookie
irb(main):012:0> c.name
=> "chrismas"

Thats normal (for me !) behaviour. Now the same with 1.9.0:

irb(main):001:0> RUBY_VERSION
=> "1.9.0"
irb(main):002:0> require 'delegate'
=> true
irb(main):003:0> class Cookie < DelegateClass(Array)
irb(main):004:1>    attr_reader :name
irb(main):005:1>    def initialize(name)
irb(main):006:2>        @name = name
irb(main):007:2>    end
irb(main):008:1> end
=> nil
irb(main):009:0>
irb(main):010:0* c = Cookie.new('chrismas')
=> nil
irb(main):011:0> c.class
=> NilClass         <--------------------- LOOK HERE ---------------------
irb(main):012:0> c.name
=> "chrismas"
irb(main):013:0> c.kind_of? Cookie
=> false              <---------------------- Surprising !!!
irb(main):014:0> c.nil?
=> true                <------------------  HUH ???
irb(main):015:0> c.__id__
=> -605609388
irb(main):016:0> nil.__id__
=> 4
irb(main):017:0> c == nil
=> true
irb(main):018:0> nil.name
NoMethodError: undefined method `name' for nil:NilClass
        from (irb):29:in `Kernel#binding'
        from /opt/ruby19/lib/ruby/1.9/delegate.rb:284
irb(main):019:0> c.name
=> "chrismas"

Hmmm... now the cookie's class is NilClass, not Cookie. We have c == 
nil, but they are clearly two different objects and only c has the 
'name' method. I will have to reconsider my understanding of ==

This behaviour make problem with cgi.rb library: when a cgi object 
ouputs it's header at line 616, the test
    options["cookie"].kind_of?(Cookie)
fails, and the cookie isn't set back properly.

Bug in cgi.rb or delegate.rb ? My bet is on the later :-)

Merry Christmas

Francois

In This Thread

Prev Next