IRB 有哪些替代方案?

发布于 2024-09-26 05:27:12 字数 172 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

阿楠 2024-10-03 05:27:12

使用 Pry:https://github.com/pry/pry

让您:

  • 启动会话
  • 在运行时视图 方法源代码
  • 查看方法文档(不使用 RI,因此您不必预先生成它)
  • 在不同的上下文中弹出和弹出
  • 语法突出显示
  • 要点 集成
  • 视图和重播历史
  • 记录 打开编辑器以使用 edit-method obj.my_method 编辑方法 语法

一吨更多伟大和原始的功能

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

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)
  • 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

A tonne more great and original features

淡墨 2024-10-03 05:27:12

真是巧合啊。 Rubyflow 昨天刚刚宣布了 irbtools gem,这是一个元宝石,包含许多很酷的 irb 增强宝石。它包含:

  • wirbfancy_irb 作为注释进行着色和输出
  • 漂亮的 IRB 提示和 IRB 的自动缩进
  • 包括 stdlib 的 FileUtils:lscdpwdln_srmmkdirtouchcat
  • 许多调试助手:apqocyObject#mObject#d
    • ap – Awesome_print
    • q – 与 p 类似,但在一行
    • Object#m – 有序方法列表(采用整数参数:嵌套级别)
    • Object#d – 放置对象,返回自身(使用tap
  • “神奇”信息常量:Info、OS ,Ruby版本,RubyEngine
    • 操作系统.windows?
    • RubyEngine.jruby?
    • RubyVersion.is.at_least? 1.9
  • 剪贴板功能:复制粘贴
    • 还提供:copy_inputcopy_output 用于会话历史记录
  • 调用 vim(或其他支持的编辑器)来编辑文件,关闭它并它会加载到您当前的 irb 会话中,由 interactive_editor 提供支持
  • 另一种实时加载到 irb 的方式:草图
  • 使用 olorize('string') 突出显示字符串或使用 < code>ray('path'),由 coderay 提供支持 使用
  • hirb 将 ActiveRecord 数据库条目显示为表格,
  • 使用 reset! 重新启动 irb或者使用 use 方法和 rvm! 更改 Ruby 版本
  • 在加载路径中包含当前目录(出于安全原因在 1.9.2 中被删除,但在IRB)
  • 更短的要求如下:rq:mathn
  • 并使用 rrq 进行重新要求
  • 尝试包含的 Object#ri 帮助程序,由 ori< 提供支持/代码>!
  • 使用 boson 访问更多命令 – 调用命令即可开始

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

2013 更新

自从我写这篇文章以来,Pry 已成为流行的 IRB 替代品。它的功能不如 irbtools 开箱即用,但它可以通过插件 gem 进行扩展,从而添加很酷的功能。您可以像浏览 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>

您还可以浏览 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:

  • Colorized and output as comment by wirb and fancy_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_print
    • q – like p, but on one line
    • Object#m – ordered method list (takes integer parameter: level of nesting)
    • Object#d – puts the object, returns self (using tap)
  • “Magical” information constants: 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
  • 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
  • Another way of live loading into irb: sketches
  • Highlight a string with olorize('string') or a file with ray('path'), powered by coderay
  • Displays ActiveRecord database entries as tables with hirb
  • Restart irb with reset! or change the Ruby version with the use method and rvm!
  • Includes the current directory in the load path (was removed in 1.9.2 for security reasons, but is pretty annoying in IRB)
  • Shorter requiring like this: rq:mathn
  • And rerquiring with rrq
  • Try the included Object#ri helper, powered by ori!
  • Access to a lot of more commands with boson – call commands to get started

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 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:

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.

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

白衬杉格子梦 2024-10-03 05:27:12

我从未听说过 IRB 的(流行)替代品,但肯定有一些有用的宝石可以使 IRB 体验变得更好:

  • awesome_print 漂亮地打印带有缩进和着色的 Ruby 对象,在尝试查看嵌套哈希或其他复杂数据结构时非常有用。
  • looksee 也非常棒,它提供了一个方法 lp (查找路径)向您显示 Ruby 对象从何处获取其方法(类、超类等)。
  • Sketches 连接你的编辑器和 IRB,所以如果你是喜欢互动的类型,它特别有用发展。带有 inf-ruby 的 Emacs 对此也很有用。
  • Wirble 是一整套 IRB 增强功能,例如制表符补全和语法突出显示。还有Utility Belt,但我个人不使用它,所以无法评论它的功能。

编辑

我忘记了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:

  • awesome_print pretty prints Ruby objects with indentation and coloring, very useful when trying to look at nested hashes or other complicated data structures.
  • 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).
  • 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.
  • 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.

Edit

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

JRuby 附带了 jirb_swing,它提供了代码完成功能。

JRuby ships with jirb_swing, which provides code completion.

这个俗人 2024-10-03 05:27:12

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.

○闲身 2024-10-03 05:27:12

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

花期渐远 2024-10-03 05:27:12

rib 是一个模块化的轻型 Rub​​y 交互式 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.

感情旳空白 2024-10-03 05:27:12

我制作了一个纯 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文