Conrad forwarded:
> # When creating a class, is "initialize" the only form of constructor?
> # 
> # Is it possible to define multiple constructors that have a different
> # set of input parameters?
> # 
> # I suspect if I want to use variable input parameters to the
> # constructor I will have to pass an array (or reference) and then
> # test for the number and type of parameters and then initialize
> # accordingly.  In otherwords do my own type matching on the parameter
> # list.

Dave's solution is a nice workaround. The fact is that we don't have any
overloading in Ruby.

I'd guess, however, that introducing some other workaround magic wouldn't be
too hard. That could be done, for example, by creating a initialize method
generator, which automatically does all the tricks to dispatch to the right
method, and creates illusion of overloaded method (to the user).

It could look like

  class Foo
    create_initialize( "MatchParametersByType", "initialize_type",
                       "ByArgumentCount", "initialize_array")
    def initialize_type_String
      # called at Foo.new("pass string")
      # dispatched by "MatchParametersByType" magic
    end
    def initialize_type_Float
      # called at Foo.new(3.1415)
      # dispatched by "MatchParametersByType" magic
    end
    ...
    def initialize_array_0
      # called at Foo.new()
      # dispatched by "ByArgumentCount" magic
    end

    def initialize_array_1
      # called at Foo.new(SomeTypeWhichWontMatchByType.new)
      # dispatched by "ByArgumentCount" magic
      # rare case, as usually initialize_type_XXX matches
    end
    ...
  end

The create_initialize basically gives the class under building for
inspection to the different dispatching code generators. They decide what
code is needed and return bunch of code which check the argument types and
counts, and whatever, and calls the right initializer.

In the end it's like using overloaded methods from the client side, and not
very far from writing overloaded methods on the class side.

If you end up writing a lot of dispatching logic into initialize just to
handle overloading, maybe you could share the create_initialize you'll
refactor out from your code. Maybe you can even prepare a library for this,
as I'd expect people could have use for it. 

(While I guess it's really a little bit against current Ruby trend: do
little, do that in right place, and coerse types as needed.)

	- Aleksi