IRB 有哪些替代品? [英] What alternatives to IRB are there?
问题描述
在 Python 世界中,有许多替代的 Python 解释器可以添加很酷的附加功能.一个特别有用的示例是 bpython,它添加了动态语法突出显示、自动拉取文档并显示实时自动完成信息.在 Ruby 世界中,我还没有发现任何添加到基本 IRB 解释器的项目,甚至是这些功能的一个子集.是我不够努力,还是 Ruby 社区缺乏这种东西?
In the python world, there are a number of alternative python interpreters that add cool additional features. One particularly useful example is bpython, which adds dynamic syntax highlighting, automatically pulls documentation, and displays live autocomplete information. In the Ruby world, I have yet to uncover any projects which add to the basic IRB interpreter even a subset of these features. Am I just not looking hard enough, or is this just something the Ruby community is lacking?
推荐答案
真巧.Rubyflow 就在昨天宣布了 irbtools gem,这是一个包含许多很酷的 irb 增强宝石的元宝石.它包含:
What a coincidence. Rubyflow just yesterday announced the irbtools gem, which is a meta-gem containing lots of cool irb enhancement gems. It contains:
- 由
wirb
和fancy_irb
着色并作为注释输出 - 漂亮的 IRB 提示和 IRB 的自动缩进
- 包括 stdlib 的 FileUtils:
ls
、cd
、pwd
、ln_s
、rm
、mkdir
、touch
、cat
- 许多调试助手:
ap
、q
、o
、c
、y
、对象#m
、对象#d
ap
– awesome_printq
– 类似于p
,但在一行上Object#m
– 有序方法列表(采用整数参数:嵌套级别)Object#d
– 放置对象,返回自身(使用tap
)
- Colorized and output as comment by
wirb
andfancy_irb
- Nice IRB prompt and IRB’s auto indention
- Includes stdlib’s FileUtils:
ls
,cd
,pwd
,ln_s
,rm
,mkdir
,touch
,cat
- Many debugging helpers:
ap
,q
,o
,c
,y
,Object#m
,Object#d
ap
– awesome_printq
– likep
, but on one lineObject#m
– ordered method list (takes integer parameter: level of nesting)Object#d
– puts the object, returns self (usingtap
)
OS.windows?
RubyEngine.jruby?
RubyVersion.is.at_least?1.9
- 也可用:
copy_input
和copy_output
用于会话历史
- also available:
copy_input
andcopy_output
for session history
irbtools 页面上有很好的屏幕截图.它的一个好处是每个实用程序都可以独立存在,以防您只想挑选一两个功能.
There are nice screenshots on the irbtools page. One nice thing about it is that each of the utilities can stand on its own, in case you just want to cherry-pick one or two features.
2013 年更新
自从我写这篇文章以来,Pry 已经成为一种流行的 IRB 替代品.它不像
irbtools
那样开箱即用,但它可以通过插件 gems 进行扩展,增加很酷的功能.您可以像浏览 unix 目录一样浏览源代码:Since I wrote this, Pry has become a popular IRB replacement. It doesn't do as much as
irbtools
out of the box, but it extensible with plugin gems that add cool features. You can browse source code like it was a unix directory:pry(main)> cd FileUtils pry(FileUtils):1> show-method rm From: /opt/ruby/lib/ruby/1.9.1/fileutils.rb @ line 556: Number of lines: 10 Owner: FileUtils def rm(list, options = {}) fu_check_options options, OPT_TABLE['rm'] list = fu_list(list) fu_output_message "rm#{options[:force] ? ' -f' : ''} #{list.join ' '}" if options[:verbose] return if options[:noop] list.each do |path| remove_file path, options[:force] end end pry(FileUtils):2>
您还可以浏览 Ruby 文档、发出 shell 命令,如果您是 Rails 用户,则可以使用
pry-rails
gem 在 Rails 控制台中获取 pry.还有一种方法可以将它连接到 Sinatra 并与 Heroku 一起使用.You can also browse Ruby documentation, issue shell commands, and if you're a Rails user, you can use the
pry-rails
gem to get pry in your Rails console. There's also a way to hook it into Sinatra and use it with Heroku.有大量的文档——有很多截屏视频,包括 Railscast.绝对值得研究.
There's ample documentation--there are a bunch of screencasts including a Railscast. It's definitely worth looking into.
这篇关于IRB 有哪些替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!