From: Yukihiro Matsumoto Date: 2008-07-04T23:35:26+09:00 Subject: Re: initialize and super with parameters Hi, In message "Re: initialize and super with parameters" on Fri, 4 Jul 2008 23:26:46 +0900, Andy Joel writes: |Some example code | |class MySuperClass | def initialize *args | puts "In SuperClass initialize" | end |end | |class MySubClass1 < MySuperClass | def initialize name | puts "In SubClass initialize: " + name | super | end |end | |The super in the subclass will take with it any parameters that were |sent to the initialize method, so this will throw an error as the |initialize in MySuperClass does not accept the same number of |parameters. | |This is surprisingly restrictive (given the nature of Ruby generally). |If you are extending a class with a parameterless initializer, you |cannot access the superclass initializer if you want to include a |parameter. Why not? You can explicitly provide arguments to super, e.g. super(arg1, arg2) to call a method of super class. You can call it without any argument by super() note that it's different from "super". matz.