# Get Parameter names from methods

**URL:** <https://www.ruby-forum.com/t/get-parameter-names-from-methods/106980>\
**Category:** Ruby\
**Created:** [June 16, 2007, 12:31am UTC](https://www.ruby-forum.com/t/get-parameter-names-from-methods/106980 "2007-06-16T00:31:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sams](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e79b87/32.png) [@sams](https://www.ruby-forum.com/u/sams)\
**Post date:** [June 16, 2007, 12:31am UTC](https://www.ruby-forum.com/t/get-parameter-names-from-methods/106980/1 "2007-06-16T00:31:22Z")

</div>

Oft asked for, here you go:

> def binding\_class  
> end  
> parameter\_name.empty? || parameter\_name == ‘nil’  
> end.map { |s| s.freeze }  
> end  
> end
> 
> ```
> parameter_names
> end
> 
> ```
> 
> end
> 
> end

There’s holes in this. It’s not a full Ruby parser. But it should work  
for 99% of your files.

The idea is to extend web MVC frameworks like Merb to allow actions  
like the following:

> class Post  
> def show(id)  
> @post = Post.find(id)  
> end  
> end

I got the idea from a .NET project based _loosely_ on Rails:  
[http://castleproject.org/monorail/index.html](http://castleproject.org/monorail/index.html)

The problem is Ruby doesn’t provide reflection similar to c#'s  
ParameterInfo object to make this easy. So here we are. I hope someone  
else finds this useful.

---

<div class="post-metadata">

**Author:** ![sams](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e79b87/32.png) [@sams](https://www.ruby-forum.com/u/sams)\
**Post date:** [June 16, 2007, 5:00am UTC](https://www.ruby-forum.com/t/get-parameter-names-from-methods/106980/2 "2007-06-16T05:00:45Z")

</div>

Uhmm, yeah. Nevermind that version. Perfection!:

> ```
> end
> 
> ```
> 
> end
> 
> end

Now any UnboundMethod (written in Ruby) can be inspected for it’s  
parameters, without any fancy require hacks…
