From: Clay Trump Date: 2012-11-03T13:46:10+09:00 Subject: [ruby-core:48796] Re: [ruby-trunk - Bug #6832][Assigned] Module#instance_method and Module#method_defined? act inconsistently w.r.t #respond_to_missing? --f46d04428dc049fd2004cd8fee55 Content-Type: text/plain; charset=ISO-8859-1 +1, at least for instance_method returning an UnboundMethod. On Fri, Nov 2, 2012 at 11:25 PM, mame (Yusuke Endoh) wrote: > > Issue #6832 has been updated by mame (Yusuke Endoh). > > Status changed from Open to Assigned > Assignee set to matz (Yukihiro Matsumoto) > Target version set to 2.0.0 > > Let me summarize: > > class Foo > def method_missing(name, *args) > return super unless name =~ /^foo_/ > puts name > end > > def respond_to_missing?(name, include_private) > super || name =~ /^foo_/ > end > end > > Foo.new.method(:foo_bar).call #=> "foo_bar" (as expected) > p Foo.method_defined?(:foo_bar) #=> true expected, but actual false > p Foo.instance_method(:foo_bar) #=> UnboundMethod expected, but actual > NameError > > Matz, is this an intended behavior? > > -- > Yusuke Endoh > ---------------------------------------- > Bug #6832: Module#instance_method and Module#method_defined? act > inconsistently w.r.t #respond_to_missing? > https://bugs.ruby-lang.org/issues/6832#change-32279 > > Author: myronmarston (Myron Marston) > Status: Assigned > Priority: Normal > Assignee: matz (Yukihiro Matsumoto) > Category: > Target version: 2.0.0 > ruby -v: 1.9.3p194 > > > It's awesome that #respond_to_missing? allows Object#method to work for > messages handled by #method_missing. However, I was surprised to discover > that Module#instance_method and Module#method_defined? don't similarly take > #respond_to_missing? into account. It seems very inconsistent. > > Here's the behavior I'm seeing: > > https://gist.github.com/3255162 > > In this example, I would expect Foo#method_defined?(:foo_bar) to return > true, and I would expect Foo#instance_method(:foo_bar) to return an > UnboundMethod that, when bound to a Foo instance, would use #method_missing > to perform the method. > > > -- > http://bugs.ruby-lang.org/ > > -- --f46d04428dc049fd2004cd8fee55 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable +1, at least for instance_method returning an UnboundMethod.

On Fri, Nov 2, 2012 at 11:25 PM, mame (Yusuke Endoh) <mam= e@tsg.ne.jp> wrote:

Issue #6832 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)
Target version set to 2.0.0

Let me summarize:

=A0 =A0 class Foo
=A0 =A0 =A0 def method_missing(name, *args)
=A0 =A0 =A0 =A0 return super unless name =3D~ /^foo_/
=A0 =A0 =A0 =A0 puts name
=A0 =A0 =A0 end

=A0 =A0 =A0 def respond_to_missing?(name, include_private)
=A0 =A0 =A0 =A0 super || name =3D~ /^foo_/
=A0 =A0 =A0 end
=A0 =A0 end

=A0 =A0 Foo.new.method(:foo_bar).call =A0 #=3D> "foo_bar" (as = expected)
=A0 =A0 p Foo.method_defined?(:foo_bar) #=3D> true expected, but actual = false
=A0 =A0 p Foo.instance_method(:foo_bar) #=3D> UnboundMethod expected, bu= t actual NameError

Matz, is this an intended behavior?

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Bug #6832: Module#instance_method and Module#method_defined? act inconsiste= ntly w.r.t #respond_to_missing?
https://bugs.ruby-lang.org/issues/6832#change-32279

Author: myronmarston (Myron Marston)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category:
Target version: 2.0.0
ruby -v: 1.9.3p194


It's awesome that #respond_to_missing? allows Object#method to work for= messages handled by #method_missing. =A0However, I was surprised to discov= er that Module#instance_method and Module#method_defined? don't similar= ly take #respond_to_missing? into account. =A0It seems very inconsistent.
Here's the behavior I'm seeing:

https://gist.= github.com/3255162

In this example, I would expect Foo#method_defined?(:foo_bar) to return tru= e, and I would expect Foo#instance_method(:foo_bar) to return an UnboundMet= hod that, when bound to a Foo instance, would use #method_missing to perfor= m the method.


--
http://bugs.ruby-l= ang.org/




--
<lay tru= m/>

--f46d04428dc049fd2004cd8fee55--