stevec
stevec

Reputation: 52738

Make interactive ruby REPL display results for consecutive commands, not only the last?

If I run this

a = "hello"

b = "world"

a
b

in ruby

irb(main):007> a = "hello"
=> "hello"
irb(main):008> b = "world"
=> "world"
irb(main):009> a
irb(main):010> b
=> "world"

in python1

>>> a = "hello"
>>> b = "world"
>>> a
'hello'
>>> b
'world'

Ruby skips the result of a (and if there were more consecutive lines of code it would skip their output too). Ruby only displays the output of the last consecutive command (in this case, b)

Question

Is there a way to force ruby to not do that, that is, if there's >1 consecutive commands, to show the results of all of them, not just the last?


1. Python is just an example, most other scripting languages too.

Upvotes: 1

Views: 135

Answers (1)

Alex
Alex

Reputation: 30036

It's a side effect of multiline editing capability in irb. The whole code block is being treated as a single command and you can edit it as a block (arrow up). There is a configuration to disable it:

# .irbrc
IRB.conf[:USE_MULTILINE] = false

# or
irb --nomultiline

# or
bin/rails c -- --nomultiline

However, there seems to be a caveat that Reline will still treat input as multiline when pasting. You'll need readline-ext installed as well:

gem install readline-ext

https://ruby.github.io/irb/index.html#label-Input+Method

Upvotes: 6

Related Questions