[Ironruby-core] Generic method synxtax

Jimmy Schementi Jimmy.Schementi at microsoft.com
Fri Jan 9 18:37:09 EST 2009

Foo.of(Bar).new works today … since it's about instantiating generic types … this discussion was only about generic methods.

From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Ryan Riley
Sent: Friday, January 09, 2009 2:33 PM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Generic method synxtax

How would this look for instantiating a generic object?

my_object = Foo.method(:new).of(Bar).call

That seems strange. Perhaps we need to possibilities: the above for generic methods and the following for generic classes:

my_object = Foo.of(Bar).new
# where Foo would be defined as Foo<T> in C#

my_clone = my_object.clone
# where clone would have a C# signature of T Clone<T>()

or should that be:

my_clone = my_object.method(:clone).of(Bar).call?
# and allow my_object.clone to have an overloaded
# C# signature of object Clone()?

On Fri, Jan 9, 2009 at 3:45 PM, Tomas Matousek <Tomas.Matousek at microsoft.com<mailto:Tomas.Matousek at microsoft.com>> wrote:

Mine has also an issue that just occurred to me. If you do:

class C

  content.load of(Texture2D), "foo"


"of" resolves to Module#of which would return a C<Texture2D> if C was a generic type or throws an exception.

So that's not good either. We would need a different method name for generic method constructor than for generic type. Maybe "method_of"?

As for your idea:


is looks backwards. The content is not of T… the load is. I think this would be confusing.

Until we figure out some nice clean solution that works in 100% cases, I would implement the following as the first step for generic method support:


(Note, you can do the same in Ruby for regular methods: "foo".method(:center).call(100))

anything else is just a convenience and anyone could define it via standard Ruby means.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090109/d91d7821/attachment.html>

More information about the Ironruby-core mailing list