From: Mat Schaffer Date: 2007-03-21T01:15:36+09:00 Subject: Re: does Ruby not support multiple "initialize" methods for a class??? On Mar 20, 10:42 am, ara.t.how...@noaa.gov wrote: > On Tue, 20 Mar 2007, Greg Hauptmann wrote: > > I have a class that can be created from a couple of scenarios, and for each > > the initial data to populate the class is different. I was going to create > > two "initialize" methods with their own specific method signature to cover > > off these two scenarios however I guess I will need to perhaps just create > > two separate/normal methods for this. Perhaps then it would be like: > > > a = Klass.new > > a.create_for_scenario_one (...) > > you can use class methods to return objects, as others have mentioned, but it > also extremely easy to do your own function signature matching in ruby In the interest of ridiculousness, how about using the multi gem for this? :) require 'rubygems' require 'multi' class Foo def initialize(*args) multi(:init, Integer) { |i| puts 'integer used' # do integer stuff... } multi(:init, Float) { |f| puts 'float used' # do float stuff... } init(*args) end end