在 IRB 中,我可以查看我之前定义的方法的来源吗? [英] In IRB, can I view the source of a method I defined earlier?

查看:38
本文介绍了在 IRB 中,我可以查看我之前定义的方法的来源吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在 IRB 中定义了一个方法,有没有什么办法可以在稍后的会话中查看它的来源?

If I define a method in IRB, is there any way to review its source later in the session?

> def my_method
>   puts "hi"
> end

几屏输出之后我希望能够写出类似

Several screens of output later I'd like to be able to write something like

> source my_method

然后回来:

=> def my_method; puts "hi"; end;

这可能吗?

推荐答案

尝试 pry.有一个关于它的 railscast(在同一周发布!)它向你展示如何使用show-method显示代码.

Try pry. There is a railscast about it (released this same week!) and it shows you how to show the code by using show-method.

这篇关于在 IRB 中,我可以查看我之前定义的方法的来源吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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