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"
的操作?
在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
按下选项+return
Voilà
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
什么对我不起作用
我的设置是使用MacOS蒙特利。所提出的解决方案("按选项+返回"(不起作用。我试了很多其他的组合键,但都不起作用。
什么对我有用
我刚刚删除了最后一行的结尾,这允许我使用";返回";插入新行,直到我再次添加结束。