Get Parameter names from methods


#1

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.


#2

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…