chopper draw lion4
chopper draw lion4

Reputation: 13487

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?

Upvotes: 0

Views: 570

Answers (2)

Stefan
Stefan

Reputation: 114138

From the documentation:

An input is executed when it is syntactically complete.

Entering incomplete expressions results in "multi-line mode", e.g. 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>

Upvotes: 2

chopper draw lion4
chopper draw lion4

Reputation: 13487

Just figured it out! I need to separate each argument with a comma.

Upvotes: 0

Related Questions