barlop
barlop

Reputation: 13743

Why might interactive ruby stop showing results?

I was just playing around with interactive ruby.

Near the beginning (line 138), I did

.  irb(main):138:0> ['rock','paper','scissors'].index('paper')
=> 1

And that above worked

Then I tried a bunch of lines 139-147 experimenting to get more used to the language

Then I wasn't getting results and I tried some even simpler things I expected would work, 148-154 and didn't get any result.

So it looks like at some point one of my commands might've stopped it from displaying results though i'm not sure what.

I'd like to get it to display the results again. I suppose I could try to exit and go back in but i'd rather a way without doing that,

.  irb(main):138:0> ['rock','paper','scissors'].index('paper')
=> 1
irb(main):139:0> a=[1,2,3
irb(main):140:1> a
irb(main):141:1> a=[1.2.3]
irb(main):142:1> a[0]
irb(main):143:1> a(0)
irb(main):144:1> a=[1,2,3]
irb(main):145:1> a(1)
irb(main):146:1> puts a(1)
irb(main):147:1> puts a[1]
irb(main):148:1> a
irb(main):149:1> a=[1,2,3]
irb(main):150:1> a
irb(main):151:1> h={4=>4}
irb(main):152:1> h
irb(main):153:1> puts 6
irb(main):154:1>

If it makes any difference this is my version number and OS is Windows.

C:\blah>ruby -v
ruby 2.1.6p336 (2015-04-13 revision 50298) [i386-mingw32]

C:\blah>

Upvotes: 0

Views: 192

Answers (2)

pimpin
pimpin

Reputation: 297

Notice that since late 2019, assignment does not output any more the value in irb. This is a new case where Interactive Ruby (irb) stop showing result.

NB : you can get the old behavior by setting IRB.conf[:ECHO_ON_ASSIGNMENT] = true in your ~/.irbrc.

Upvotes: 1

sevenseacat
sevenseacat

Reputation: 25029

Because of this line here:

irb(main):139:0> a=[1,2,3

You haven't closed off the array with a closing ]. the :1 in irb(main):154:1> makes it clear you're inside a nested expression.

If you enter another ], you'll get a big syntax error because all of what you've entered before it isn't valid array syntax, but then you can move on.

Upvotes: 2

Related Questions