Determining if initialize is defined in child class

J

Jim Freeze

Hi

I am looking for a method that will tell me if a method
is defined in a child class. The problem is when looking
at child classes for with the parent has the method in
question defined.

class C
private_method_defined?:)fred) #=> false
private_method_defined?:)initialize) #=> true
end

Is there some method that will return false for the above
initialize method:

class C
method_defined_in_this_class?(fred:) #=> false
method_defined_in_this_class?:)initialize) #=> false
def fred; end
method_defined_in_this_class?(fred:) #=> true
end

Ultimately I want to be able to do the following:

class Parent
def initialize; end
end

class Child < Parent
method_defined_in_this_class?:)initialize) #=> false
end
 
E

Eric Mahurin

--- Jim Freeze said:
Hi
=20
I am looking for a method that will tell me if a method
is defined in a child class. The problem is when looking
at child classes for with the parent has the method in
question defined.
=20
class C
private_method_defined?:)fred) #=3D> false
private_method_defined?:)initialize) #=3D> true
end
=20
Is there some method that will return false for the above
initialize method:
=20
class C
method_defined_in_this_class?(fred:) #=3D> false
method_defined_in_this_class?:)initialize) #=3D> false
def fred; end
method_defined_in_this_class?(fred:) #=3D> true
end
=20
Ultimately I want to be able to do the following:
=20
class Parent
def initialize; end
end
=20
class Child < Parent
method_defined_in_this_class?:)initialize) #=3D> false
end


How about this:

private_instance_methods(false).include?("initialize")




=09
____________________________________________________
Sell on Yahoo! Auctions =96 no fees. Bid on great items. =20
http://auctions.yahoo.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,944
Members
47,491
Latest member
mohitk

Latest Threads

Top