# Reflection - Defined methods in controller

**URL:** <https://www.ruby-forum.com/t/reflection-defined-methods-in-controller/121241>\
**Category:** Rails\
**Created:** [November 25, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/reflection-defined-methods-in-controller/121241 "2007-11-25T23:16:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [November 25, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/reflection-defined-methods-in-controller/121241/1 "2007-11-25T23:16:01Z")

</div>

I’m trying to get a list of the methods that I’ve defined in a  
controller. But,

“controller.methods” is giving me ALL the methods of the controller. Is  
there a way to get the only the methods that I’ve defined?

Cheers

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [November 26, 2007, 12:01am UTC](https://www.ruby-forum.com/t/reflection-defined-methods-in-controller/121241/2 "2007-11-26T00:01:14Z")

</div>

Luke :

> I’m trying to get a list of the methods that I’ve defined in a  
> controller. But,
> 
> “controller.methods” is giving me ALL the methods of the controller. Is  
> there a way to get the only the methods that I’ve defined?

ActionController::Base.action\_methods and  
ActionController::Base#action\_methods give you a set  
of your actions.

If you want the public methods defined just in your controller, you’ve  
got MyController.public\_instance\_methods(false)

HTH,

```
-- Jean-François.
```

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [November 26, 2007, 12:26am UTC](https://www.ruby-forum.com/t/reflection-defined-methods-in-controller/121241/3 "2007-11-26T00:26:33Z")

</div>

action\_methods returns an array, and you can subtract one array from  
another.  
so to get just the actions for that controller, you could do this in  
script/console:

MyController.action\_methods - ApplicationController.action\_methods

On Nov 26, 1:00 am, “Jean-François Trân” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [November 26, 2007, 2:39am UTC](https://www.ruby-forum.com/t/reflection-defined-methods-in-controller/121241/4 "2007-11-26T02:39:05Z")

</div>

> MyController.public\_instance\_methods(false)

Awesome, worked like a charm. Thanks.
