简体   繁体   中英

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?

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?

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

$ 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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