Issue #4994 has been updated by Sylvain Viart.
Sorry, but links are in Japanese.
I can read the code, but not why the DelegateClass shouldn't search the global public method, any more?
Could you translate or post a link to an English doc?
For the correction you suggest, I've wrote this code:
I don't like this usage as a Delegation. May be I missed something.
<pre>
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)
bla()
end
def method_missing(m, *args, &block)
begin
Object.send(m, *args, &block)
rescue NameError =>e
# doesn't work with NoMethodError, it loops
raise "no method found: '#{m}'"
end
end
end
s2 = String2.new("pipo")
# test Delegated method
pp s2.size
# call with method_missing()
pp s2.dummy
</pre>
output (ruby -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux])
<pre>
:!ruby draft/tdelegate.rb
4
draft/tdelegate.rb:24:in `rescue in method_missing': no method found: 'bla' (RuntimeError)
from draft/tdelegate.rb:20:in `method_missing'
from draft/tdelegate.rb:16:in `dummy'
from draft/tdelegate.rb:32:in `<main>'
</pre>
----------------------------------------
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:
<pre>
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
</pre>
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:
<pre>
!ruby draft/tdelegate.rb
draft/tdelegate.rb:15:in `dummy': undefined method `test_that?' for "pipo":String2 (NoMethodError)
from draft/tdelegate.rb:21:in `<main>'
shell returned 1
</pre>
--
http://redmine.ruby-lang.org