Forum: Ruby Get Parameter names from methods

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sam S. (Guest)
on 2007-06-16 02:31
(Received via mailing list)
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

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.
Sam S. (Guest)
on 2007-06-16 07:00
(Received via mailing list)
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...
This topic is locked and can not be replied to.