Strange message when superclass expression raises an error

I was using “class Foo < foo … end” where “foo” is some arbitrary
expression, not necessarily a constant. I found that when "foo"
raises an error the result is quite (IMHO) misleading. For example:

irb(main):001:0> def foo ; raise “foo” end
=> nil
irb(main):002:0> Class.new(foo)
RuntimeError: foo
from (irb):1:in `foo’
from (irb):2
irb(main):003:0> class Foo < foo ; end
TypeError: superclass undefined
from (irb):1
irb(main):004:0>

“superclass undefined”? What happened to the real error? If Ruby had
reported the original error properly it would have saved me a certain
amount of frustration. Surely the error should simply propagate to
top level, just as when calling Class.new(foo) ?

Regards,

Jeremy Henty

"superclass undefined"? What happened to the real error? If Ruby had
reported the original error properly it would have saved me a certain
amount of frustration. Surely the error should simply propagate to
top level, just as when calling Class.new(foo) ?

Well, this is changed in 1.8.0

pigeon% ruby -ve 'def foo ; raise "foo" end; class Foo < foo; end'
ruby 1.8.0 (2003-01-09) [i686-linux]
-e:1:in `foo': foo (RuntimeError)
        from -e:1
pigeon%

Guy Decoux

Oops, I should have said I was using 1.6.8 . Another reason to
upgrade, I guess. Thanks for checking it out.

Cheers,

Jeremy Henty

···

In article 200301121412.h0CECXl06292@moulon.inra.fr, ts wrote:

“superclass undefined”? … Surely the error should simply
propagate to top level

Well, this is changed in 1.8.0

pigeon% ruby -ve ‘def foo ; raise “foo” end; class Foo < foo; end’
ruby 1.8.0 (2003-01-09) [i686-linux]
-e:1:in `foo’: foo (RuntimeError)
from -e:1