有什么替代IRB的方法吗?

时间:2021-11-17 16:57:16

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?

在python世界中,有许多可供选择的python解释器,它们添加了很酷的附加特性。一个特别有用的示例是bpython,它添加动态语法突出显示、自动提取文档并显示实时自动完成信息。在Ruby世界中,我还没有发现任何项目可以添加到基本的IRB解释器中,甚至是其中的一部分。我只是不够努力,还是这只是Ruby社区所缺乏的东西?

9 个解决方案

#1


29  

What a coincidence. Rubyflow just yesterday announced the irbtools gem, which is a meta-gem containing lots of cool irb enhancement gems. It contains:

什么是巧合。Rubyflow昨天刚刚发布了irbtools gem,它是一个包含了许多cool irb增强宝石的元宝石。它包含:

  • Colorized and output as comment by wirb and fancy_irb
  • 由wirb和fancy_irb注释着色和输出
  • Nice IRB prompt and IRB’s auto indention
  • 很好的IRB提示和IRB的自动缩进。
  • Includes stdlib’s FileUtils: ls, cd, pwd, ln_s, rm, mkdir, touch, cat
  • 包括stdlib的文件库:ls, cd, pwd, ln_s, rm, mkdir, touch, cat
  • Many debugging helpers: ap, q, o, c, y, Object#m, Object#d
    • ap – awesome_print
    • 美联社- awesome_print
    • q – like p, but on one line
    • 像p,但是在一条直线上
    • Object#m – ordered method list (takes integer parameter: level of nesting)
    • 对象#m -有序方法列表(取整型参数:嵌套级别)
    • Object#d – puts the object, returns self (using tap)
    • 对象#d -放置对象,返回self(使用tap)
  • 许多调试助手:ap, q, o, c, y,对象#m,对象#d ap - awesome_print q -类似p,但是在一行对象#m -有序方法列表(取整型参数:嵌套级别)
  • “Magical” information constants: Info, OS, RubyVersion, RubyEngine
    • OS.windows?
    • OS.windows吗?
    • RubyEngine.jruby?
    • RubyEngine.jruby吗?
    • RubyVersion.is.at_least? 1.9
    • RubyVersion.is.at_least吗?1.9
  • “魔法”信息常量:Info、OS、RubyVersion、RubyEngine OS.windows?RubyEngine.jruby吗?RubyVersion.is.at_least吗?1.9
  • Clipboard features: copy and paste
    • also available: copy_input and copy_output for session history
    • 还有可用的:会话历史的copy_input和copy_output。
  • 剪贴板特性:复制和粘贴也可用:会话历史的copy_input和copy_output
  • Call vim (or another supported editor) to edit a file, close it and it gets loaded into your current irb session, powered by interactive_editor
  • 调用vim(或另一个受支持的编辑器)来编辑一个文件,关闭它,它将被加载到当前的irb会话中,由interactive_editor提供支持
  • Another way of live loading into irb: sketches
  • 另一种实时载入irb的方式是:草图
  • Highlight a string with olorize('string') or a file with ray('path'), powered by coderay
  • 用olorize('string')突出显示一个字符串,或者用ray('path')突出显示一个由coderay支持的文件
  • Displays ActiveRecord database entries as tables with hirb
  • 使用hirb将ActiveRecord数据库条目显示为表
  • Restart irb with reset! or change the Ruby version with the use method and rvm!
  • 重启irb和重置!或者使用use方法和rvm修改Ruby版本!
  • Includes the current directory in the load path (was removed in 1.9.2 for security reasons, but is pretty annoying in IRB)
  • 包含加载路径中的当前目录(出于安全原因,在1.9.2中删除了,但是在IRB中非常烦人)
  • Shorter requiring like this: rq:mathn
  • 更短的要求:rq:mathn。
  • And rerquiring with rrq
  • 和rerquiring rrq
  • Try the included Object#ri helper, powered by ori!
  • 尝试包含的对象#ri助手,由ori提供动力!
  • Access to a lot of more commands with boson – call commands to get started
  • 开始使用boson - call命令访问更多命令

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.

irbtools页面上有很好的屏幕截图。它的一个好处是,每个实用程序都可以独立运行,以防您只是想挑选一两个特性。

2013 Update

2013年更新

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已经成为一个流行的IRB替代品。它不像irbtools那样一开始就做的那么多,但是它可以通过插件gems来扩展,它可以添加很酷的特性。您可以像浏览unix目录一样浏览源代码:

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>

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.

您还可以浏览Ruby文档,发出shell命令,如果您是Rails用户,您可以使用pry- Rails gem在Rails控制台中获取pry。也有一种方法可以把它和辛纳屈连在一起,和赫鲁库一起使用。

There's ample documentation--there are a bunch of screencasts including a Railscast. It's definitely worth looking into.

有充足的文档——有一大堆的视频,包括一个Railscast。这绝对值得一看。

#2


34  

Use Pry: http://pry.github.com

使用撬:http://pry.github.com

Let's you:

让你:

  • start sessions at runtime
  • 开始运行时会话
  • view method source code
  • 视图方法的源代码
  • view method documentation (not using RI so you dont have to pre-generate it)
  • 查看方法文档(不使用RI,所以您不必预先生成它)
  • pop in and out of different contexts
  • 在不同的上下文中弹出
  • syntax highlighting
  • 语法高亮显示
  • gist integration
  • 依据集成
  • view and replay history
  • 视图和重演历史
  • open editors to edit method using edit-method obj.my_method syntax
  • 打开编辑器使用编辑方法obj编辑方法。my_method语法

A tonne more great and original features

更多伟大和原创的特征

#3


3  

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:

我从来没有听说过一个(流行的)替代IRB的方法,但是确实有一些有用的宝石可以让IRB的体验更好:

  • awesome_print pretty prints Ruby objects with indentation and coloring, very useful when trying to look at nested hashes or other complicated data structures.
  • awesome_print漂亮地打印带有缩进和着色的Ruby对象,在尝试查看嵌套散列或其他复杂数据结构时非常有用。
  • looksee is pretty awesome too, it provides a method lp (lookup path) that shows you where a Ruby object gets its methods from (class, superclass etc).
  • looksee也非常棒,它提供了一个方法lp(查找路径),它向您展示了Ruby对象从何处获取它的方法(类、超类等)。
  • Sketches connects your editor and IRB, so it's especially useful if you are the type who likes interactive development. Emacs with inf-ruby is also good for this.
  • 草图连接了您的编辑器和IRB,所以如果您是喜欢交互开发的类型,那么它特别有用。使用inf-ruby的Emacs也很好。
  • Wirble is a whole set of IRB enhancements, like tab completion and syntax highlighting. There's also Utility Belt, but I don't personally use that, so can't comment on its features.
  • Wirble是一整套IRB增强功能,如tab补全和语法高亮。还有实用腰带,但我个人不使用它,所以不能评论它的功能。

Edit

编辑

I forgot Hirb, which is very useful for e.g. showing the results of an ActiveRecord query in a Rails console.

我忘记了Hirb,它非常有用,例如在Rails控制台中显示ActiveRecord查询的结果。

#4


2  

There's http://github.com/alloy/dietrb.

这是http://github.com/alloy/dietrb。

#5


2  

JRuby ships with jirb_swing, which provides code completion.

JRuby附带了jirb_swing,后者提供代码完成。

#6


1  

There's not much in the area of alternatives to irb, but there are a couple of gems that add useful features to irb.

除了irb之外,irb的替代方案不多,但是有一些宝石可以为irb添加有用的特性。

Most notably wirble, which, among other things, gives you colored output (not input though) and a history that goes beyond the current session.

最值得注意的是wirble,它提供有颜色的输出(虽然不是输入)和超越当前会话的历史。

#7


1  

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?.

看看ripl,一个模块化的irb替代品,它被设计成可扩展的。您可能还会从Ruby中获得一些类似bpython的答案。

#8


0  

rib is a modular and light Ruby interactive shell.

罗纹是一个模块化的轻Ruby交互外壳。

It, like Pry, uses Ruby's parser so has consistent behavior with Ruby thus less bugs (e.g. https://*.com/a/39271791/474597)

它与Pry一样,使用Ruby的解析器,因此与Ruby具有一致的行为,从而减少了bug(例如https://*.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.

截至2016年,它仍在积极维护。

#9


0  

I made a pure Ruby console, inspired off Google Chrome's JavaScript console.

我制作了一个纯Ruby控制台,灵感来自谷歌Chrome的JavaScript控制台。

https://github.com/sancarn/RubyConsole

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.

它仍然主要是一个WIP项目,因为我一直在用当前的算法查找bug,但是我正在将其构建为1.9.3+兼容。

#1


29  

What a coincidence. Rubyflow just yesterday announced the irbtools gem, which is a meta-gem containing lots of cool irb enhancement gems. It contains:

什么是巧合。Rubyflow昨天刚刚发布了irbtools gem,它是一个包含了许多cool irb增强宝石的元宝石。它包含:

  • Colorized and output as comment by wirb and fancy_irb
  • 由wirb和fancy_irb注释着色和输出
  • Nice IRB prompt and IRB’s auto indention
  • 很好的IRB提示和IRB的自动缩进。
  • Includes stdlib’s FileUtils: ls, cd, pwd, ln_s, rm, mkdir, touch, cat
  • 包括stdlib的文件库:ls, cd, pwd, ln_s, rm, mkdir, touch, cat
  • Many debugging helpers: ap, q, o, c, y, Object#m, Object#d
    • ap – awesome_print
    • 美联社- awesome_print
    • q – like p, but on one line
    • 像p,但是在一条直线上
    • Object#m – ordered method list (takes integer parameter: level of nesting)
    • 对象#m -有序方法列表(取整型参数:嵌套级别)
    • Object#d – puts the object, returns self (using tap)
    • 对象#d -放置对象,返回self(使用tap)
  • 许多调试助手:ap, q, o, c, y,对象#m,对象#d ap - awesome_print q -类似p,但是在一行对象#m -有序方法列表(取整型参数:嵌套级别)
  • “Magical” information constants: Info, OS, RubyVersion, RubyEngine
    • OS.windows?
    • OS.windows吗?
    • RubyEngine.jruby?
    • RubyEngine.jruby吗?
    • RubyVersion.is.at_least? 1.9
    • RubyVersion.is.at_least吗?1.9
  • “魔法”信息常量:Info、OS、RubyVersion、RubyEngine OS.windows?RubyEngine.jruby吗?RubyVersion.is.at_least吗?1.9
  • Clipboard features: copy and paste
    • also available: copy_input and copy_output for session history
    • 还有可用的:会话历史的copy_input和copy_output。
  • 剪贴板特性:复制和粘贴也可用:会话历史的copy_input和copy_output
  • Call vim (or another supported editor) to edit a file, close it and it gets loaded into your current irb session, powered by interactive_editor
  • 调用vim(或另一个受支持的编辑器)来编辑一个文件,关闭它,它将被加载到当前的irb会话中,由interactive_editor提供支持
  • Another way of live loading into irb: sketches
  • 另一种实时载入irb的方式是:草图
  • Highlight a string with olorize('string') or a file with ray('path'), powered by coderay
  • 用olorize('string')突出显示一个字符串,或者用ray('path')突出显示一个由coderay支持的文件
  • Displays ActiveRecord database entries as tables with hirb
  • 使用hirb将ActiveRecord数据库条目显示为表
  • Restart irb with reset! or change the Ruby version with the use method and rvm!
  • 重启irb和重置!或者使用use方法和rvm修改Ruby版本!
  • Includes the current directory in the load path (was removed in 1.9.2 for security reasons, but is pretty annoying in IRB)
  • 包含加载路径中的当前目录(出于安全原因,在1.9.2中删除了,但是在IRB中非常烦人)
  • Shorter requiring like this: rq:mathn
  • 更短的要求:rq:mathn。
  • And rerquiring with rrq
  • 和rerquiring rrq
  • Try the included Object#ri helper, powered by ori!
  • 尝试包含的对象#ri助手,由ori提供动力!
  • Access to a lot of more commands with boson – call commands to get started
  • 开始使用boson - call命令访问更多命令

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.

irbtools页面上有很好的屏幕截图。它的一个好处是,每个实用程序都可以独立运行,以防您只是想挑选一两个特性。

2013 Update

2013年更新

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已经成为一个流行的IRB替代品。它不像irbtools那样一开始就做的那么多,但是它可以通过插件gems来扩展,它可以添加很酷的特性。您可以像浏览unix目录一样浏览源代码:

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>

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.

您还可以浏览Ruby文档,发出shell命令,如果您是Rails用户,您可以使用pry- Rails gem在Rails控制台中获取pry。也有一种方法可以把它和辛纳屈连在一起,和赫鲁库一起使用。

There's ample documentation--there are a bunch of screencasts including a Railscast. It's definitely worth looking into.

有充足的文档——有一大堆的视频,包括一个Railscast。这绝对值得一看。

#2


34  

Use Pry: http://pry.github.com

使用撬:http://pry.github.com

Let's you:

让你:

  • start sessions at runtime
  • 开始运行时会话
  • view method source code
  • 视图方法的源代码
  • view method documentation (not using RI so you dont have to pre-generate it)
  • 查看方法文档(不使用RI,所以您不必预先生成它)
  • pop in and out of different contexts
  • 在不同的上下文中弹出
  • syntax highlighting
  • 语法高亮显示
  • gist integration
  • 依据集成
  • view and replay history
  • 视图和重演历史
  • open editors to edit method using edit-method obj.my_method syntax
  • 打开编辑器使用编辑方法obj编辑方法。my_method语法

A tonne more great and original features

更多伟大和原创的特征

#3


3  

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:

我从来没有听说过一个(流行的)替代IRB的方法,但是确实有一些有用的宝石可以让IRB的体验更好:

  • awesome_print pretty prints Ruby objects with indentation and coloring, very useful when trying to look at nested hashes or other complicated data structures.
  • awesome_print漂亮地打印带有缩进和着色的Ruby对象,在尝试查看嵌套散列或其他复杂数据结构时非常有用。
  • looksee is pretty awesome too, it provides a method lp (lookup path) that shows you where a Ruby object gets its methods from (class, superclass etc).
  • looksee也非常棒,它提供了一个方法lp(查找路径),它向您展示了Ruby对象从何处获取它的方法(类、超类等)。
  • Sketches connects your editor and IRB, so it's especially useful if you are the type who likes interactive development. Emacs with inf-ruby is also good for this.
  • 草图连接了您的编辑器和IRB,所以如果您是喜欢交互开发的类型,那么它特别有用。使用inf-ruby的Emacs也很好。
  • Wirble is a whole set of IRB enhancements, like tab completion and syntax highlighting. There's also Utility Belt, but I don't personally use that, so can't comment on its features.
  • Wirble是一整套IRB增强功能,如tab补全和语法高亮。还有实用腰带,但我个人不使用它,所以不能评论它的功能。

Edit

编辑

I forgot Hirb, which is very useful for e.g. showing the results of an ActiveRecord query in a Rails console.

我忘记了Hirb,它非常有用,例如在Rails控制台中显示ActiveRecord查询的结果。

#4


2  

There's http://github.com/alloy/dietrb.

这是http://github.com/alloy/dietrb。

#5


2  

JRuby ships with jirb_swing, which provides code completion.

JRuby附带了jirb_swing,后者提供代码完成。

#6


1  

There's not much in the area of alternatives to irb, but there are a couple of gems that add useful features to irb.

除了irb之外,irb的替代方案不多,但是有一些宝石可以为irb添加有用的特性。

Most notably wirble, which, among other things, gives you colored output (not input though) and a history that goes beyond the current session.

最值得注意的是wirble,它提供有颜色的输出(虽然不是输入)和超越当前会话的历史。

#7


1  

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?.

看看ripl,一个模块化的irb替代品,它被设计成可扩展的。您可能还会从Ruby中获得一些类似bpython的答案。

#8


0  

rib is a modular and light Ruby interactive shell.

罗纹是一个模块化的轻Ruby交互外壳。

It, like Pry, uses Ruby's parser so has consistent behavior with Ruby thus less bugs (e.g. https://*.com/a/39271791/474597)

它与Pry一样,使用Ruby的解析器,因此与Ruby具有一致的行为,从而减少了bug(例如https://*.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.

截至2016年,它仍在积极维护。

#9


0  

I made a pure Ruby console, inspired off Google Chrome's JavaScript console.

我制作了一个纯Ruby控制台,灵感来自谷歌Chrome的JavaScript控制台。

https://github.com/sancarn/RubyConsole

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.

它仍然主要是一个WIP项目,因为我一直在用当前的算法查找bug,但是我正在将其构建为1.9.3+兼容。