From: dblack@... Date: 2006-10-26T11:01:56+09:00 Subject: Re: Calling functions in a child class Hi -- On Thu, 26 Oct 2006, Brian Schlect wrote: > I have a class: > > class alpha > def test_method > puts "test method" > end > > def get_methods > puts alpha.methods > end > end It's a little unclear what you're doing here. "class alpha" won't parse (alpha isn't a constant), and since test_method is not defined as a class method, it won't appear when you do alpha.methods. > running "get_methods" here will return a long list of methods including > test_method. But, I also have this class: > > class bravo < alpha > def another_test_method > end > end > > i want to be able to call get_methods in the parent class and have it > return the functions of the child class as well. so in this example: > > test_obj = bravo.new > bravo.get_methods > > would return all methods including > > test_method > another_test_method See if this does what you need: class Alpha def test_method end def get_methods p self.class.instance_methods.sort # for easy viewing :-) end end Alpha.new.get_methods class Bravo < Alpha def another_test_method end end Bravo.new.get_methods David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org