【问题标题】:How can I add a new line in Ruby 2.7+ IRB multiline edit mode?如何在 Ruby 2.7+ IRB 多行编辑模式下添加新行?
【发布时间】:2021-01-01 16:56:47
【问题描述】:

Ruby 2.7 对IRB 进行了更新,允许进行多行编辑。如何在多行方法中添加新行以在前两个语句之间注入代码?

例如

2.7.1 :019 > while session = server.accept
2.7.1 :020 >   session.puts "Hello World! The time is #{Time.now}"
2.7.1 :021 >   session.close
2.7.1 :022 > end

如何在第 21 行的 session.close 之前添加新行,以便可以执行 session.puts "closing connection" 之类的操作?

【问题讨论】:

    标签: ruby read-eval-print-loop irb


    【解决方案1】:

    在 OS X 保留选项上,然后在您想换行的行上按回车键。

    例如

    2.7.1 :019 > while session = server.accept
    2.7.1 :020 >   session.puts "Hello World! The time is #{Time.now}" # cursor here
    2.7.1 :021 >   session.close
    2.7.1 :022 > end
    

    选项+返回

    2.7.1 :019 > while session = server.accept
    2.7.1 :020 >   session.puts "Hello World! The time is #{Time.now}"
    2.7.1 :021 >   
    2.7.1 :022 >   session.close
    2.7.1 :023 > end
    

    【讨论】:

    • 我的直觉是 Linux / Windows 的组合键与 meta 或 alt + return 类似。
    • 明白了。这是在 Mojave 上使用 bash 完成的。 zsh 中是否有超过option 使用的元键?
    猜你喜欢
    • 1970-01-01
    • 2016-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多