"Michael Weller" <michael / gutschi.de> schrieb im Newsbeitrag
news:bur719$l36i8$1 / ID-105305.news.uni-berlin.de...
> Hi!
> I have some experience with programming in other languages, but I'm new
> to Ruby.
> Here's a problem I encoutered writing my first program:
> I got these two classes, both classes are defined in the same file
> (let's call it "modA"):
>
> <code>
> class A
> def initialize
> #inits some instance variables
> end
> end
>
> class B < A
> def initialize(x, y)
> super
> @myX = x
> @myY = y
> end
> end
> </code>
>
> If I create instances of B in the same file (!), everything is OK
> (e.g.:
> b = B.new('sth', 'anotherSth')
> puts b.toS
> ).
>
> But if create another file and 'include modA' and do the same all I get
> is this:
> ./blogdata.rb:23:in `initialize': wrong number of arguments(0 for 2)
> (ArgumentError)
> from ./blogdata.rb:23:in `new'
> from ./blogdata.rb:23:in `initialize'
> from ./blogdata.rb:32:in `initialize'
> from UI.rbw:5:in `new'
> from UI.rbw:5
>
> So it seems like B is trying to pass the two params it received on to A.
> A doesn't define 'initialize' with two params to I get an error.
> I looked in the "Ruby Man Docs" and on the syntax page the author
states:
> "the super invokes the method which the current method overrides. If no
> arguments given, arguments to the current method passed to the method."
>
> My questions:
> Can I change this behaviour? Do I need to introduce an "initialize(a,b)'
> in my A class? Why does it work if my code is written in the same file?

For me it doesn't work in the same file.  It should always throw as Guy
pointed out already.  I guess you might have tested something different
(maybe you forgot "< A" in one of the files).

Cheers

    robert