On Tue, Apr 23, 2013 at 10:42 PM, Matthew Kerwin <lists / ruby-forum.com> wrote:
> Julio Olivera wrote in post #1106717:
>> If you try it on http://repl.it/, $- immediately returns nil. Perhaps on
>> irb the interpreter is waiting for more input? I can't test it right
>> now,
>> but what happens if you write something like the following?
>>
>>> $-x = 42
>>> $-
>>> x
>>
>> Julio
>> @_joliv <http://twitter.com/_joliv>
>>
>
> I think that's the right track.  There's something a little bit magic
> going on in IRB, because the second line is treated as a whole new line,
> thus:
>
> irb(main):001:0> $-x = 42
> => 42
> irb(main):002:0> $-
> irb(main):003:0> x
> NameError: undefined local variable or method `x' for main:Object
>   from (irb):3
>   from /usr/local/bin/irb21:12:in `<main>'
> irb(main):004:0> $-
> irb(main):005:0> 1
> => 1
>
> Whatever it is, I guess the upshot is "don't use $- at the end of a line
> in IRB".
>

A little off-topic, what _not_ to put at the end of lines in IRB also
applies to the symbol literals :- and :+ .
In a previous conversation...

https://groups.google.com/d/msg/ruby-talk-google-deleted-39f2c/GPfpRGASBwo/g9UAU0kLzkQJ

...the issue of IRB parsing, specifically with specific characters as
the last character of a line, came up and similar IRB behavior was
noticed then.

$ irb
1.9.3p194 :001 > x = :-
1.9.3p194 :002 >
1.9.3p194 :003 >   "hi"
 => "hi"
1.9.3p194 :004 > x
 => :-

So yeah, the working theory then was that any valid token who's last
character looks like an operator ($-, :-, :+, others?) will make IRB
think the line isn't finished. I guess someone could just read IRB's
code to verify....

--
Kendall Gifford
zettabyte / gmail.com