简体   繁体   English

如何在不输入数据的情况下在交互式红宝石中键入新行?

[英]How do you type on a new line in interactive ruby without inputting the data?

In Python's IDLE if you press shift+Enter you can begin typing on a newline, what is the Ruby equivalent? 在Python的IDLE中,如果按shift + Enter,你可以开始在换行符上输入,Ruby等价物是什么?

I am trying to pass arguments to a function using a hash argument and would like to be able to span each hash item on its own line. 我试图使用哈希参数将参数传递给函数,并希望能够在自己的行上跨越每个哈希项。 How can I do this in interactive Ruby? 我怎么能在交互式Ruby中做到这一点?

From the documentation : 文档

An input is executed when it is syntactically complete. 输入在语法完成时执行。

Entering incomplete expressions results in "multi-line mode", eg starting a hash with { enter 输入不完整的表达式会导致“多行模式”,例如使用{ enter开始哈希

$ irb
irb(main):001:0> {
irb(main):002:1*   foo: 1,
irb(main):003:1*   bar: 2
irb(main):004:1> }
#=> {:foo=>1, :bar=>2}
irb(main):005:0>

Just figured it out! 刚想通了! I need to separate each argument with a comma. 我需要用逗号分隔每个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM