From: Trygve Flathen Date: 2011-07-23T19:41:35+09:00 Subject: code ok in ruby, but fails in irb 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/.