The current implementation of RubyCLR breaks identity with respect to interfaces. You will have multiple Ruby shadow class objects the moment you try to do something like:
enumerator = obj.as(IEnumerable).get_enumerator.as(IEnumerator)
At the recent Ruby Summit at Lang.Net last week, we discussed this problem among others.
The solution that IronPython uses is this:
enumerator = IEnumerable.get_enumerator(obj)
So get_enumerator is effectively a static method on an IEnumerable type. While there are other corner cases to consider, I think that this is going to be the ultimate solution to interfaces and identity in RubyCLR.
Thoughts welcome.
1 archived reader comment
Charles Oliver Nutter (2006/08/09)
We’re wrestling with the interface question this week at the JRuby project. Currently JRuby supports including Java code into the current file like so: include_class "path.to.Interface" and implementation of interfaces works like this: class MyImpl < Interface … end This is a design decision we inherited, but we’re on the verge of changing such behavior because of the obvious limitations of extension-for-implementation. However the "proxy" class that’s created for the interface should always be the same class everywhere. This is because: - we have a runtime where we can store such things, and - you must explicitly pull in Java types to the Ruby world So we always end up using the same proxy once it’s been drawn into Ruby world.