From: Sylvain Viart Date: 2011-07-20T21:59:25+09:00 Subject: [ruby-core:38259] [Ruby 1.9 - Bug #4994] DelegateClass don't find extern global public method in 1.9.2 Issue #4994 has been updated by Sylvain Viart. Fixed DelegateClass with method_missing(), somewhat ugly right?
require 'delegate'

def hello
    :hello
end

class MyInt < DelegateClass(Integer)
    def initialize(value)
        @i = value
        super(@i)
        # I want some toplevel here
        @hello = hello()
    end

    def method_missing(m, *args, &block)
        if __getobj__.respond_to?(m)
            __getobj__.__send__(m, *args, &block)
        else
            Object.send(m, *args, &block)
        end
    end
end

ii = MyInt.new(2)
puts p"should call Integer#to_si: #{ii}"
puts "ii.class=#{ii.class}"
output ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
should call Integer#to_si: 2
ii.class=MyInt
---------------------------------------- Bug #4994: DelegateClass don't find extern global public method in 1.9.2 http://redmine.ruby-lang.org/issues/4994 Author: Sylvain Viart Status: Rejected Priority: Normal Assignee: Category: lib Target version: 1.9.2 ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux] How to reproduce:
require 'delegate'
require 'pp'

def test_that?(str)
    str.size > 0
end

class String2 < DelegateClass(String)
    def initialize(*param)
        @s = String.new(*param)
        super(@s)
    end

    def dummy
        test_that?(@s)
    end
end

s2 = String2.new("pipo")

pp s2.dummy
The code above works under 1.9.1 and 1.8 but not under 1.9.2 * ruby1.9.1 -v => ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux] * ruby1.8 -v => ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] * ruby -v => ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux] error message:
!ruby draft/tdelegate.rb
draft/tdelegate.rb:15:in `dummy': undefined method `test_that?' for "pipo":String2 (NoMethodError)
        from draft/tdelegate.rb:21:in `
' shell returned 1
-- http://redmine.ruby-lang.org