From: Josh Cheek Date: 2011-07-23T21:18:19+09:00 Subject: Re: code ok in ruby, but fails in irb --90e6ba4fc2f0acac1004a8bb93c7 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Jul 23, 2011 at 5:41 AM, Trygve Flathen wrote: > The following statement, with the newline, is ok with ruby but generates > a syntax error in irb: > > "#{ begin "#{3}" end > }" > > I expect that ruby and irb should have the same idea of what constitutes > legal code? > > I encountered the problem while testing this function: > > def maketable(infohash) > "#{ > infohash.collect{|k,v| > "" > }.join > }
#{k}#{v}
" > end > > Dump from test terminal: > > sh-4.1$ ruby -v > ruby 1.8.7 (2011-02-18 patchlevel 334) [i386-linux] > sh-4.1$ cat x.rb > "#{ begin "#{3}" end > }" > sh-4.1$ ruby x.rb > sh-4.1$ irb > irb(main):001:0> "#{ begin "#{3}" end }" > => "3" > irb(main):002:0> "#{ begin "#{3}" end > SyntaxError: compile error > (irb):2: syntax error, unexpected $end, expecting '}' > from (irb):2 > from :0 > > -- > Posted via http://www.ruby-forum.com/. > > Works for me on 1.9, but not on 1.8 It's worth updating, IMO. 1.9 is faster, newer, better in almost every way. There is already talk of EOL for 1.8, it won't be supported much longer. --90e6ba4fc2f0acac1004a8bb93c7--