相关疑难解决方法(0)

如何在ruby中列出当前作用域中当前可用的对象?

我是红宝石的新手,我正在玩IRB.

我发现我可以使用".methods"方法列出对象的方法,而self.methods类似于我想要的东西(类似于Python的dir(builtins)?),但我怎样才能找到方法库/模块我通过include和require加载?

irb(main):036:0* self.methods
=> ["irb_pop_binding", "inspect", "taguri", "irb_chws", "clone", "irb_pushws", "public_methods", "taguri=", "irb_pwws",
"public", "display", "irb_require", "irb_exit", "instance_variable_defined?", "irb_cb", "equal?", "freeze", "irb_context
", "irb_pop_workspace", "irb_cwb", "irb_jobs", "irb_bindings", "methods", "irb_current_working_workspace", "respond_to?"
, "irb_popb", "irb_cws", "fg", "pushws", "conf", "dup", "cwws", "instance_variables", "source", "cb", "kill", "help", "_
_id__", "method", "eql?", "irb_pwb", "id", "bindings", "send", "singleton_methods", "popb", "irb_kill", "chws", "taint",
 "irb_push_binding", "instance_variable_get", "frozen?", "irb_source", "pwws", "private", "instance_of?", "__send__", "i
rb_workspaces", "to_a", "irb_quit", "to_yaml_style", "irb_popws", "irb_change_workspace", "jobs", "type", "install_alias
_method", "irb_push_workspace", "require_gem", …
Run Code Online (Sandbox Code Playgroud)

ruby introspection irb

34
推荐指数
4
解决办法
3万
查看次数

Ruby相当于Python的帮助()?

在交互式Python中工作时,我倾向于依靠内置help()函数来告诉我期望和/或返回的内容,并打印出可能对我有帮助的任何文档.有没有Ruby相当于这个功能?

我正在寻找一些我可以在irb中使用的东西.例如,在交互式Python中我可以输入:

>>> help(1)
Run Code Online (Sandbox Code Playgroud)

然后打印

Help on int object:

class int(object)  |  int(x[, base])
-> integer  |    |  

Convert a string or number to an integer, if possible. A ...
Run Code Online (Sandbox Code Playgroud)

ruby python

19
推荐指数
3
解决办法
5175
查看次数

标签 统计

ruby ×2

introspection ×1

irb ×1

python ×1