I get a core dump when executing the following code.
class Bob
[‘hi’, ‘hello’, ‘howdy’, ‘goodbye’].each do |mname|
instance_eval <<-EOF
def #{mname}
puts #{mname}
end
EOF
end
end
Bob.hi
I get the same behavior when using eval instead of instance_eval and
calling “Bob.new.hi”. I know that the code isn’t valid, but a core
dump seems inappropriate (maybe a SyntaxError exception?). And my
Ruby interpreter is a little old.
I’m happy to provide any further information that would be helpful.
Enjoy!
Ryan
It works correctly for me (ruby 1.8.7 (2008-08-11 patchlevel 72)
[i686-linux])
Stefano
Sorry, I was wrong. I missed the last line when copying the text. The
code
doesn’t work, but it doesn’t give a core dump, but simply a
SystemStackError
exception.
You have left out the quotes in << puts #{name} >>. This results in
(for example):
def hi
puts hi
end
…which results in the function calling itself forever. On my machine
(exact same Ruby version and patchlevel, but on Windows) I get a
SystemStackError:
(eval):2:in hi': stack level too deep (SystemStackError) from (eval):2:in hi’
But it’s understandable that you core dump instead.
I get the same behavior when using eval instead of instance_eval and
calling “Bob.new.hi”. I know that the code isn’t valid, but a core
dump seems inappropriate (maybe a SyntaxError exception?). And my
Ruby interpreter is a little old.