任何ruby库来检查某些方法的参数是什么? [英] Any ruby library to inspect what are the arguments that a certain methods take?

查看:121
本文介绍了任何ruby库来检查某些方法的参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何库可以检查并显示方法所采用的参数?

is there any library that can inspect and display what are the arguments that a method takes?

推荐答案

了解任何第三方库或甚至可以可靠地执行此操作的RubyGems。考虑到Ruby提供的有限反射设施,这种检查是不可能的。

I don't know of any third-party libraries or even RubyGems that can do this reliably. It just isn't possible to do this kind of inspection given the limited reflection facilities Ruby provides.

您必须完成核心库中可用的功能,这基本上是 方法#参数

You will have to make do with what is available in the core library, which is basically Method#parameters:

def foo(a, b=nil, *c, d, &e); end
method(:foo).parameters
  # => [[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:block, :e]]

这篇关于任何ruby库来检查某些方法的参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆