From: merch-redmine@... Date: 2021-02-26T21:59:17+00:00 Subject: [ruby-core:102622] [Ruby master Bug#9931] irb: Really weird behavior for x = "#{x\"}" (ex: irb(main:009:-4)) Issue #9931 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Assigned to Closed As of Ruby 3.0, I think this is fixed: ``` $ irb30 irb(main):001:0" x = "#{x\"}" irb(main):002:0" irb(main):003:0" } irb(main):004:0" " Traceback (most recent call last): 3: from /usr/local/bin/irb30:23:in `
' 2: from /usr/local/bin/irb30:23:in `load' 1: from /usr/local/lib/ruby/gems/3.0/gems/irb-1.3.0/exe/irb:11:in `' SyntaxError ((irb):1: syntax error, unexpected backslash) x = "#{x\"}" ^ ``` This behavior makes sense. It's invalid syntax, so it is reasonable that irb would expect that after `"#{x\"}"`, you are still in an interpolation inside a string, and as soon as it knows the interpolation has ended, it evaluates the string and you get a syntax error. ---------------------------------------- Bug #9931: irb: Really weird behavior for x = "#{x\"}" (ex: irb(main:009:-4)) https://bugs.ruby-lang.org/issues/9931#change-90616 * Author: jesserayadkins (Jesse Adkins) * Status: Closed * Priority: Normal * Assignee: aycabta (aycabta .) * ruby -v: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- # Our journey starts off rather simple: irb(main):001:0> x = "#{x}" => "" # Okay, makes sense. irb(main):002:0> x = "#{x\"}" irb(main):003:0" # Hmm...Still in a string? That's weird. irb(main):003:0" " irb(main):004:0> # Things seem back to normal but... irb(main):004:0> x # Nothing? But x is defined! irb(main):005:0> # Nothing? Hmm... irb(main):005:0> end irb(main):006:-1> end # Uhh...I don't think that's supposed to do that. irb(main):007:-2> end irb(main):008:-3> end irb(main):009:-4> # ...I'm afraid to go deeper. # Get me out of here! irb(main):009:-4> quit irb(main):010:-4> # O.O irb(main):010:-4> ^C irb(main):010:0> # ...Can I go now? irb(main):010:0> quit # Success! # Additionally, if I put this in a file: x = "#{x\"}" # I get two syntax errors (ruby 1.9.3): test.rb:1: syntax error, unexpected $undefined, expecting '}' x = "#{x\"}" ^ test.rb:1: syntax error, unexpected $end, expecting '}' x = "#{x\"}" ^ -- https://bugs.ruby-lang.org/ Unsubscribe: