https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112011-07-09T07:51:14ZRuby Issue Tracking SystemRuby master - Bug #4994: DelegateClass don't find extern global public method in 1.9.2https://bugs.ruby-lang.org/issues/4994?journal_id=189572011-07-09T07:51:14Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>It's a spec change for <a href="https://blade.ruby-lang.org/ruby-dev/39154">[ruby-dev:39154]</a>.</p>
<ul>
<li>Delegator now tries to forward all methods as possible,</li>
<li>but not for private methods, and</li>
<li>test_that? is a private method.</li>
</ul>
<p>Probably, it would need a way to tell how the method is called in method_missing.</p> Ruby master - Bug #4994: DelegateClass don't find extern global public method in 1.9.2https://bugs.ruby-lang.org/issues/4994?journal_id=192932011-07-18T17:15:55Zsylvain303 (Sylvain Viart)
<ul></ul><p>Sorry, but links are in Japanese.<br>
I can read the code, but not why the DelegateClass shouldn't search the toplevel method, any more?</p>
<p>Could you translate or post a link to an English doc?</p>
<p>For the correction you suggest, I've wrote this code:<br>
I don't like this usage as a Delegation. May be I missed something.</p>
<p>Edited: Wrong solution, for this method_missing() see comment after</p>
<pre>
require 'delegate'
require 'pp'
def test_that?(str)
str.size > 0
end
class String2 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>
<p>output (ruby -v ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux])</p>
<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 `'
</pre> Ruby master - Bug #4994: DelegateClass don't find extern global public method in 1.9.2https://bugs.ruby-lang.org/issues/4994?journal_id=193902011-07-20T19:37:19Zsylvain303 (Sylvain Viart)
<ul></ul><p>The Issue topic could be rewritten: "DelegateClass don't lookup toplevel method in 1.9.2"</p>
<p>Reading and patching the delegate.rb:<a href="http://redmine.ruby-lang.org/projects/ruby-19/repository/entry/lib/delegate.rb" class="external">http://redmine.ruby-lang.org/projects/ruby-19/repository/entry/lib/delegate.rb</a> I've found that it's related to BasicObject's behavior. DelegateClass somewhat inherit from BasicObject, not Object.</p>
<p>This issue follow the same pattern as <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: Constant Lookup doesn't work in a subclass of BasicObject (Rejected)" href="https://bugs.ruby-lang.org/issues/3768">#3768</a>.</p>
<p>The documentation should be updated how to fix that (toplevel method resolution).</p>
<p>But may be, I'm still miss something about the new Spec about DelegateClass.</p> Ruby master - Bug #4994: DelegateClass don't find extern global public method in 1.9.2https://bugs.ruby-lang.org/issues/4994?journal_id=193942011-07-20T21:59:24Zsylvain303 (Sylvain Viart)
<ul></ul><p>Fixed DelegateClass with method_missing(), somewhat ugly right?</p>
<pre>
require 'delegate'
def hello
:hello
end
class MyInt
<p>output ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]</p>
<pre>
should call Integer#to_si: 2
ii.class=MyInt
</pre></pre>