IRB 有哪些替代方案?
在 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
使用 Pry:https://github.com/pry/pry
让您:
edit-method obj.my_method 编辑方法
语法一吨更多伟大和原始的功能
Use Pry: https://github.com/pry/pry
Let's you:
edit-method obj.my_method
syntaxA tonne more great and original features
真是巧合啊。 Rubyflow 昨天刚刚宣布了 irbtools gem,这是一个元宝石,包含许多很酷的 irb 增强宝石。它包含:
wirb
和fancy_irb
作为注释进行着色和输出ls
、cd
、pwd
、ln_s
、rm
、mkdir
、touch
、cat
ap
、q
、o
、c
、y
、Object#m
、Object#d
ap
– Awesome_printq
– 与p
类似,但在一行Object#m
– 有序方法列表(采用整数参数:嵌套级别)Object#d
– 放置对象,返回自身(使用tap
)Info、OS ,Ruby版本,RubyEngine
操作系统.windows?
RubyEngine.jruby?
RubyVersion.is.at_least? 1.9
复制
和粘贴
copy_input
和copy_output
用于会话历史记录vim
(或其他支持的编辑器)来编辑文件,关闭它并它会加载到您当前的 irb 会话中,由interactive_editor
提供支持olorize('string')
突出显示字符串或使用 < code>ray('path'),由 coderay 提供支持 使用hirb
将 ActiveRecord 数据库条目显示为表格,reset!
重新启动irb
或者使用use
方法和rvm!
更改 Ruby 版本rq:mathn
rrq
进行重新要求Object#ri
帮助程序,由ori< 提供支持/代码>!
boson
访问更多命令 – 调用命令即可开始irbtools 上有很好的屏幕截图 页面。它的一个好处是,每个实用程序都可以独立存在,以防您只想挑选一两个功能。
2013 更新
自从我写这篇文章以来,Pry 已成为流行的 IRB 替代品。它的功能不如 irbtools 开箱即用,但它可以通过插件 gem 进行扩展,从而添加很酷的功能。您可以像浏览 unix 目录一样浏览源代码:
您还可以浏览 Ruby 文档、发出 shell 命令,如果您是 Rails 用户,则可以使用
pry-rails
gem 来获取 pry在 Rails 控制台中。还有一种方法可以将其连接到 Sinatra 并与 Heroku 一起使用。有充足的文档——有很多截屏视频,包括 Railscast。这绝对值得研究。
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
andfancy_irb
ls
,cd
,pwd
,ln_s
,rm
,mkdir
,touch
,cat
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
)Info, OS, RubyVersion, RubyEngine
OS.windows?
RubyEngine.jruby?
RubyVersion.is.at_least? 1.9
copy
andpaste
copy_input
andcopy_output
for session historyvim
(or another supported editor) to edit a file, close it and it gets loaded into your current irb session, powered byinteractive_editor
olorize('string')
or a file withray('path')
, powered by coderayhirb
irb
withreset!
or change the Ruby version with theuse
method andrvm!
rq:mathn
rrq
Object#ri
helper, powered byori
!boson
– call commands to get startedThere 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 Update
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: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.There's ample documentation--there are a bunch of screencasts including a Railscast. It's definitely worth looking into.
我从未听说过 IRB 的(流行)替代品,但肯定有一些有用的宝石可以使 IRB 体验变得更好:
lp
(查找路径)向您显示 Ruby 对象从何处获取其方法(类、超类等)。inf-ruby
的 Emacs 对此也很有用。编辑
我忘记了Hirb ,这对于在 Rails 控制台中显示 ActiveRecord 查询的结果非常有用。
I've never heard of a (popular) alternative to IRB, but there certainly are several useful gems that make the IRB experience a lot nicer:
lp
(lookup path) that shows you where a Ruby object gets its methods from (class, superclass etc).inf-ruby
is also good for this.Edit
I forgot Hirb, which is very useful for e.g. showing the results of an ActiveRecord query in a Rails console.
有 http://github.com/alloy/dietrb。
There's http://github.com/alloy/dietrb.
JRuby 附带了 jirb_swing,它提供了代码完成功能。
JRuby ships with
jirb_swing
, which provides code completion.irb 的替代品并不多,但有一些 gem 可以为 irb 添加有用的功能。
最值得注意的是 wirble,除其他外,它还为您提供彩色输出(但不是输入)和历史记录这超出了本届会议的范围。
There's not much in the area of alternatives to irb, but there are a couple of gems that add useful features to irb.
Most notably wirble, which, among other things, gives you colored output (not input though) and a history that goes beyond the current session.
查看 ripl,这是一个模块化的 irb 替代方案,设计为可扩展。您还可以从 Ruby 有类似 bpython 的东西吗? 得到一些答案。
Check out ripl, a modular irb alternative which is designed to be extendable. You may also get some answers from Is there something like bpython for Ruby?.
rib 是一个模块化的轻型 Ruby 交互式 shell。
与 Pry 一样,它使用 Ruby 的解析器,因此与 Ruby 具有一致的行为,从而减少错误(例如 https://stackoverflow.com/a/39271791 /474597)
它是模块化的,因此可以轻松地扩展它以提供更多功能。
截至 2016 年,它仍然得到积极维护。
rib is a modular and light Ruby interactive shell.
It, like Pry, uses Ruby's parser so has consistent behavior with Ruby thus less bugs (e.g. https://stackoverflow.com/a/39271791/474597)
It is modular so one can easily extend it with more functionalities.
It is also still actively maintained as of 2016.
我制作了一个纯 Ruby 控制台,灵感来自 Google Chrome 的 JavaScript 控制台。
https://github.com/sancarn/RubyConsole
它仍然主要是一个 WIP 项目,因为我不断发现错误使用当前的算法,但是我正在将其构建为 1.9.3+ 兼容。
I made a pure Ruby console, inspired off Google Chrome's JavaScript console.
https://github.com/sancarn/RubyConsole
It's still mostly a WIP project as I keep finding bugs with the current algorithm, however I'm building it to be 1.9.3+ compatible.