is it bug?

C

Chung Chung

Hi, all
[root@home1 ~]# ruby -v
ruby 1.9.0 (2007-06-30 patchlevel 0) [i686-linux]
[root@home1 ~]# irb
irb(main):001:0> class C
irb(main):002:1> def C.hello
irb(main):003:2> p "helloc"
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> class A < C
irb(main):007:1> def A.hello
irb(main):008:2> p "C #{hello}"
irb(main):009:2> end
irb(main):010:1> hello
irb(main):011:1> end
(irb):8:in `hello': stack level too deep (SystemStackError)
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
... 6881 levels...
 
S

Stefan Rusterholz

Chung said:
Hi, all
[root@home1 ~]# ruby -v
ruby 1.9.0 (2007-06-30 patchlevel 0) [i686-linux]
[root@home1 ~]# irb
irb(main):001:0> class C
irb(main):002:1> def C.hello
irb(main):003:2> p "helloc"
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> class A < C
irb(main):007:1> def A.hello
irb(main):008:2> p "C #{hello}"
irb(main):009:2> end
irb(main):010:1> hello
irb(main):011:1> end

It is not a bug. You recursively call A.hello. You want:
p "C #{super}"

Regards
Stefan
 
D

Daniel Martin

Quoting Chung Chung said:
Hi, all
[root@home1 ~]# ruby -v
ruby 1.9.0 (2007-06-30 patchlevel 0) [i686-linux]
[root@home1 ~]# irb
irb(main):001:0> class C
irb(main):002:1> def C.hello
irb(main):003:2> p "helloc"
irb(main):004:2> end
irb(main):005:1> end
=3D> nil
irb(main):006:0> class A < C
irb(main):007:1> def A.hello
irb(main):008:2> p "C #{hello}"
irb(main):009:2> end
irb(main):010:1> hello
irb(main):011:1> end
(irb):8:in `hello': stack level too deep (SystemStackError)
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
from (irb):8:in `hello'
... 6881 levels...

Why would you consider this a bug? What on earth were you expecting =20
it to do? You define a method with no arguments that always calls =20
itself, and then you call it, and ruby complains from the infinite =20
recursion.

What else would you have it do?

--=20
@/=3Dmap{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/;
map{y/X_/\n /;print}map{pop@$_}@/for@/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top