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

I expect that ruby and irb should have the same idea of what
constitutes legal code?

Nope. And that’s why I never use irb (nor similar toys in other
languages).

Josh C. wrote in post #1012566:

It’s worth updating, IMO. 1.9 is faster, newer, better in almost every
way.

… apart from the train wreck of Encodings (IMO - just giving a
different point of view).

On Sat, Jul 23, 2011 at 5:41 AM, Trygve Flathen
[email protected]wrote:

sh-4.1$ ruby -v
(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.