Forum: Ruby-dev [ruby-trunk - Bug #6241][Assigned] Module#method_defined? with inherited flag

F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2012-04-01 02:02
(Received via mailing list)
Issue #6241 has been reported by nobu (Nobuyoshi Nakada).

----------------------------------------
Bug #6241: Module#method_defined? with inherited flag
https://bugs.ruby-lang.org/issues/6241

Author: nobu (Nobuyoshi Nakada)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0
ruby -v: 35201


=begin
Currently (({Module#method_defined?})) does not accept "(({inherited}))"
flags as (({Module#instance_methods})) and others.
To tell if a method is defined at an exact class/module, we have to use
bad idiom:

  mod.instance_methods(false).include?(:foo)

So I propose to let (({method_defined?})) and etc accept the flag.
=end
45196398e9685000d195ec626d477f0e?d=identicon&s=25 Thomas Sawyer (7rans)
on 2012-04-01 23:06
(Received via mailing list)
Issue #6241 has been updated by trans (Thomas Sawyer).


I think this is certainly a good idea. But I want to also point out that
it's not always ideal either b/c #method_defined? reports false for
private/protected methods. So in cases where the method in question
might have known visibility one would have to do:

    if method_defined?(:foo) or private_method_defined?(:foo) or
protected_method_defined?(:foo)

which sucks. Of course, this has always been an issue with
#instance_methods too.

Perhaps now that named parameters are coming into their own, the
interface should be modified to handle options?

    method_defined?(:foo, all: true, inherited: false)


----------------------------------------
Feature #6241: Module#method_defined? with inherited flag
https://bugs.ruby-lang.org/issues/6241#change-25575

Author: nobu (Nobuyoshi Nakada)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


=begin
Currently (({Module#method_defined?})) does not accept "(({inherited}))"
flags as (({Module#instance_methods})) and others.
To tell if a method is defined at an exact class/module, we have to use
bad idiom:

  mod.instance_methods(false).include?(:foo)

So I propose to let (({method_defined?})) and etc accept the flag.
=end
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 matz (Yukihiro Matsumoto) (Guest)
on 2012-10-30 18:19
(Received via mailing list)
Issue #6241 has been updated by matz (Yukihiro Matsumoto).

Status changed from Assigned to Rejected
Target version changed from 2.0.0 to next minor

Tomas has a point. We cannot accept the original idea.
So I reject this proposal. Try again.

In general I am not a big fun of inherited flag, since most inheritance
works rather as composition in Ruby.

Matz.

----------------------------------------
Feature #6241: Module#method_defined? with inherited flag
https://bugs.ruby-lang.org/issues/6241#change-32034

Author: nobu (Nobuyoshi Nakada)
Status: Rejected
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: next minor


=begin
Currently (({Module#method_defined?})) does not accept "(({inherited}))"
flags as (({Module#instance_methods})) and others.
To tell if a method is defined at an exact class/module, we have to use
bad idiom:

  mod.instance_methods(false).include?(:foo)

So I propose to let (({method_defined?})) and etc accept the flag.
=end
This topic is locked and can not be replied to.