First of all, I have no strong opinion about this issue. The current behavior of irb looks weird to me, but it may be okay because irb users can work around the issue easily.
In principle, I expect irb to cut the shortest lines that parses. For example, consider the following input:
foo
.bar
Irb first evaluates only the first line foo
, and the second line .bar
causes SyntaxError. This is the behavior that I expect. In the same logic, I expect 1..
to be cut because it parses.
irb(main):001:0> 1..
BTW, a line obj.+
causes line continuation. This is a behavior that I don't expect:
irb(main):001:0> obj = Object.new
=> #<Object:0x0000560275fa4b00>
irb(main):002:0> def obj.+(); 42; end
=> :+
irb(main):003:0> obj.+
irb(main):004:0*
irb(main):005:0* ;
=> 42
If the method name is different than +
, say foo
, irb does not wait for the next line. Looks very inconsistent.
irb(main):006:0> def obj.foo(); 42;end
=> :foo
irb(main):007:0> obj.foo
=> 42
So, I cannot see any consistent policy about line continuation.
But again, it's okay to me in the case of irb. Few users will encounter such a corner case. Even if someone does, s/he can avoid such a behavior by explicit semicolon or parens or something else.