From: James Edward Gray II Date: 2006-09-26T22:26:24+09:00 Subject: Re: constructor calls parent On Sep 26, 2006, at 8:15 AM, David Corticchiato wrote: > Hi > > I have a class witch inherit from another. I want that the child's > constructor call the upper constructor before start his (sorry for my > bad english). > > in C++ it would be : > MyClass::MyClass(options) : upperClass(options){ > > } > > I don't find how to write it in Ruby. >> class Parent >> def initialize >> puts "Parent#initialize called." >> end >> end => nil >> class Child < Parent >> def initialize >> super # call Parent#initialize with our parameters >> puts "Child#initialize called." >> end >> end => nil >> Child.new Parent#initialize called. Child#initialize called. => # If you would rather pass no arguments to the parent, use super(). To control which arguments are passed use this form: super(:passed, "arguments", 4, :parent). Hope that helps. James Edward Gray II