From: Gavin Kistner Date: 2005-07-13T21:42:13+09:00 Subject: Re: Initialization via a Module --Apple-Mail-1--930081269 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Jul 12, 2005, at 10:20 PM, Daniel Brockman wrote: > Call `super' from `initialize'. Gleah, of course. My library was fine, my use of it was broken. Thanks :) I did discover this, problem, however: module Foo attr_reader :foo def initialize( *args ) super @foo = 'foo' end end class Bar include Foo def initialize super @bar = 'bar' end end b = Bar.new p b.foo #=> "foo" class Bar2 include Foo def initialize( bar_value ) super @bar = bar_value end end b2 = Bar2.new( 'bar2' ) /Users/gavinkistner/Desktop/tmp.rb:5:in `initialize': wrong number of arguments (1 for 0) (ArgumentError) from /Users/gavinkistner/Desktop/tmp.rb:5:in `initialize' from /Users/gavinkistner/Desktop/tmp.rb:23:in `initialize' from /Users/gavinkistner/Desktop/tmp.rb:28:in `new' from /Users/gavinkistner/Desktop/tmp.rb:28 Obviously I can leave the call to #super out of my module, and leave it up to the consumer of my module to know that including mine means that any inherited class's initialization won't be called, unless the user explicitly looks for that ancestor and binds and so on. But that seems gross. Is there a good solution for writing a module's initialize so that it can properly pass initialization to the parent class first? Something longwinded involving arity checking? --Apple-Mail-1--930081269--