Simple question concerning overloading

Mathias Weyel ha scritto:

Hello!

I am quite new to Ruby and come directly from the world of Java. While the lack of a static type system has proven to be somehow irritating to me, I have stepped over a rather small problem concerning overloading of methods and parameter names. In Java, this problem cannot occur due to the static type system.

notice that there are modules (such as the poorly named StrongTyping or types.rb) that allow you to attach type information to methods, even allowing overloading. Also there is a module from Florian Gross (IIRC, ans sorry for not typing the 'b' :slight_smile: that allows you to use real MMD.

<snip>

class Whatever {
  List objects;
  public void remove(Object o) {...}
  public void remove(int i) {...}
}

The problem in converting this code to Ruby is that the remove method has no type and, because of this, cannot be overloaded this way. While having only one method and checking the type of the given argument manually seems somehow wrong to me, I wonder, how to call the parameter. The int parameter I would normally call "index" while the object parameter would correspond to the objects stored in the list. What name should the parameter get? I want to have a name that actually makes sense, but "objectOrIndex" seems stupid.

why do you feel the need to have a single method?
I mean, they're actually doing differen things, so why not:
  class Foo
   def remove_object(obj)..end
   def remove_index(idx)..end
  end

HTH

"gabriele renzi" <rff_rff@remove-yahoo.it> schrieb im Newsbeitrag news:Vqold.31698$Es2.683518@twister2.libero.it...

See also
http://www.rubygarden.org/ruby?MethodOverloading
http://www.rubygarden.org/ruby?RubyFromCpp

    robert