【发布时间】:2011-10-03 20:16:53
【问题描述】:
有没有一种快速的方法来输出 ruby 方法的可能参数名称?
例如:
def my_method(param1, param2, param3, ...)
# stuff
end
puts get_params("my_method")
会输出类似的东西:
param1
param2
param3
...
谢谢!
哦,顺便说一句,我在 ree-1.8.7...
【问题讨论】:
-
Getting Argument Names In Ruby Reflection 的可能重复项 - 原始问题的要求略高,但 Jorg Mittag 的回答回答了您的问题。
-
即使是第一个回复也有一些非常有用的见解,谢谢伙计
-
还有其他几个重复项:Is there a way to return a method parameter names in ruby、Reflection on method parameters in Ruby、Any ruby library to inspect what are the arguments that a certain methods take? 和 How do i get the names or arguments inside the method definition?。我想是时候给 StackOverflow 添加某种搜索功能了,也许是右上角的一个文本框?
-
对不起,我应该早点编辑我的帖子。我正在使用没有 Method#parameters 的 ree-1.8.7,如下所述。 ;)我认为我可以使用 local_Variables,虽然并不理想。
标签: ruby printing parameters