从 irb 获取所有局部变量或可用方法? [英] Get all local variables or available methods from irb?

查看:43
本文介绍了从 irb 获取所有局部变量或可用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我进入 irb 并输入一个不存在的命令时,我收到一条错误消息

When I go into irb and type in a command that does not exist I get an error stating

"undefined local variable or method 'my_method' for main:Object (NameError)"

有没有办法只获取可用的局部变量或方法的列表?这对于探索 ruby​​ 非常有用.

Is there a way to just get a list of what local variables or methods ARE available? This would be really useful for exploring ruby.

推荐答案

在内核、对象和模块中查找方法:例如local_variables, instance_methods, instance_variables.

Look for methods in the Kernel, Object and Module : e.g. local_variables, instance_methods, instance_variables.

还有其他很棒的方法.inspect 是另一个.

Other great methods in there. inspect is another one.

这篇关于从 irb 获取所有局部变量或可用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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