问题描述
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
按选项 + 返回
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