Brian Schlect wrote:
> I have a class:
> 
> class alpha
>  def test_method
>   puts "test method"
>  end
> 
>  def get_methods
>   puts alpha.methods
>  end
> end
> 
> 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

Did you mean this?

   test_obj.get_methods

Then a simple solution is:

class Alpha
  def test_method
   puts "test method"
  end

  def get_methods(include_methods_inherited_by_alpha = false)
   if include_methods_inherited_by_alpha
     methods
   else
     methods - Alpha.superclass.instance_methods
   end
  end
end

alpha = Alpha.new
p alpha.get_methods
#p alpha.get_methods(true)
puts

class Bravo < Alpha
  def another_test_method
  end
end

bravo = Bravo.new
p bravo.get_methods
#p bravo.get_methods(true)

__END__

Output:

["get_methods", "test_method"]

["get_methods", "test_method", "another_test_method"]


-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407