Feature #6241

Module#method_defined? with inherited flag

Added by Nobuyoshi Nakada about 2 years ago. Updated over 1 year ago.

[ruby-dev:45483]
Status:Rejected
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:core
Target version:next minor

Description

=begin
Currently (({Module#methoddefined?})) does not accept "(({inherited}))" flags as (({Module#instancemethods})) 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

0001-inherited-flag.patch Magnifier (8.69 KB) Nobuyoshi Nakada, 04/01/2012 09:01 AM


Related issues

Related to ruby-trunk - Feature #5673: undef_method probably doesn't need to raise an error Feedback 11/26/2011

History

#1 Updated by Nobuyoshi Nakada about 2 years ago

  • Tracker changed from Bug to Feature

#2 Updated by Thomas Sawyer about 2 years ago

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 not 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)

#3 Updated by Yukihiro Matsumoto over 1 year ago

  • 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.

Also available in: Atom PDF