IRB - unfinished expression at operator's symbol?

403 views Asked by At

Can anybody explain why some of operator symbols cann't be written directly as symbols in irb, whereas when passed to ruby interpreter it runs without any issue ? It looks like irb parses an expression as unfinished and prompts with an asterisk as awaiting continue of input:

irb> test_symbol = :+
irb*  ^C
irb> test_symbol = :-
irb*  ^C
irb> test_symbol = :*
=> :*
irb> test_symbol = :<
=> :<

Other symbols that fail at parsing are :%, :&, :^, :/, :|, :~ . I can pass those symbols as strings, ie. test_symbol = :'+' however this is just a workaround to a possible bug. Or a feature ?

Can somebody shed some light to this behaviour ?

1

There are 1 answers

1
Zajn On

I installed 1.9.3dev on my machine and can confirm that irb does appear to be "awaiting input" after using a symbol like that.

However, this doesn't actually affect how the eval loop functions. As an example, I tried this:

irb(main):001:0> test_symbol = :+
irb(main):002:0* 2.send test_symbol, 1
=> 3

So while it seems that IRB is waiting for you to finish an expression, it does seemt to parse the expression correctly. I can't find any bug reports around this issue.