# Ruby interpreter bug?

**URL:** <https://www.ruby-forum.com/t/ruby-interpreter-bug/147909>\
**Category:** Ruby\
**Created:** [September 6, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/ruby-interpreter-bug/147909 "2008-09-06T22:20:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpheath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rpheath](https://www.ruby-forum.com/u/rpheath)\
**Post date:** [September 6, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/ruby-interpreter-bug/147909/1 "2008-09-06T22:20:37Z")

</div>

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.

$ ruby --version  
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-freebsd6]

I’m happy to provide any further information that would be helpful.

Enjoy!

- Ryan

---

<div class="post-metadata">

**Author:** ![rpheath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rpheath](https://www.ruby-forum.com/u/rpheath)\
**Post date:** [September 6, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/ruby-interpreter-bug/147909/2 "2008-09-06T22:23:32Z")

</div>

On Saturday 06 September 2008, Ryan H. wrote:

> end  
> 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

---

<div class="post-metadata">

**Author:** ![rpheath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rpheath](https://www.ruby-forum.com/u/rpheath)\
**Post date:** [September 6, 2008, 10:31pm UTC](https://www.ruby-forum.com/t/ruby-interpreter-bug/147909/3 "2008-09-06T22:31:45Z")

</div>

On Saturday 06 September 2008, Stefano C. wrote:

> > end
> > 
> > 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.

Stefano

---

<div class="post-metadata">

**Author:** ![rpheath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rpheath](https://www.ruby-forum.com/u/rpheath)\
**Post date:** [September 7, 2008, 12:23am UTC](https://www.ruby-forum.com/t/ruby-interpreter-bug/147909/4 "2008-09-07T00:23:33Z")

</div>

On Sep 6, 9:19 pm, Ryan H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end  
> Bob.hi

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.

Hope this helps.

Rico

---

<div class="post-metadata">

**Author:** ![rpheath](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/73ab20/32.png) [@rpheath](https://www.ruby-forum.com/u/rpheath)\
**Post date:** [September 6, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/ruby-interpreter-bug/147909/5 "2008-09-06T22:27:38Z")

</div>

Hi –

On Sun, 7 Sep 2008, Ryan H. wrote:

> 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.
> 
> $ ruby --version  
> ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-freebsd6]

It’s actually not a syntax error; it’s infinite recursion, because  
you’ve got:

def hi  
puts hi  
end

so it calls itself. So it should give you this:

(eval):2:in `hi’: stack level too deep (SystemStackError)

or equivalent. Can you try it with a more recent 1.8.6?

David
