From: Trans Date: 2005-12-06T11:33:02+09:00 Subject: Re: Overloaded constructors in Ruby Timothy makes good points, but just so you understand how to write alernate constructors for Ruby there are two weys. First one can define alternate constructors: class GravPoint # however you wish to name them... def self.new_zero() new(0, 0, 0, 0, 0) end def self.new_lite(x, y, strength) new(x, y, strength, 0, 0) end def initialize(x, y, strength, ctime, life) @x, @y, @strength, @ctime, @life = x, y, strength, ctime, life end end The other way is the use variable parameters. Something like: def initialize(*args) x, y, strength, ctime, life = 0,0,0,0,0 case args.length when 0 # good just the way it is, skip when 3 x, y, strength = *args when 5 x, y, strength, ctime, life = *args else raise ArgumentError end @x, @y, @strength, @ctime, @life = x, y, strength, ctime, life end T.