John Lam 1997 — 2026

RubyCLR and method name conflicts

RubyCLR uses method_missing to dynamically bind and generate shim methods to call CLR methods. But what happens if there’s a name conflict with a method in a base class or a mixin?

I just ran into this today while updating all of the samples to run on the latest bits. Since I’m now integrating ActiveRecord support into RubyCLR, I found that calls to XamlReader.load() wouldn’t work. Digging a bit deeper, this was due to ActiveSupport defining a load method on the Object class. The way to fix this problem is to simply call XamlReader.Load, which is the “real” name of the method (as defined in the library).

Now, how can I make this experience suck less for less experienced users? Should I reflect over all of the methods of the CLR type when I create the Ruby shadow class for the CLR class and issue a ‘warning’ when it discovers method conflicts?

Suggestions welcome.

2 archived reader comments

Patrick Parks (2006-07-28)

John,

I’m just getting started with RubyCLR so don’t have a lot of context to ask my questions. But I have worked on building reflection-based interfaces from dynamical languages to Java. In that work, I ran into similar issue with name conflicts myself.

Have you decided how to resolve this issue of name resolution for base classes / mixins??? I didn’t see any comments or follow up on this other than 28 iterations of Nice Site / Thank You.

I would also like to know how you handle name resolution between classes when the same name occurs in several required libraries. My question is whether you choose one and push ahead happily (as the saltypickle bridge appeared to do) or give an error (and in a dynamic language that means what runs fine one day suddenly stops working the next day). Both approaches have pros and cons but neither of them make me very happy. I’m curious how you approach this problem in RubyCLR.

Finally, where do you suggest I start reading your blogs in order to track your adventure with building RubyCLR. I’m especially interested in your decision making process and what you have learned about dynamic binding to CLR and CIL code generation.

THANKS… NICE SITE

Pat

Stefan Wenig (2009-03-04)

John,

Here’s a question about a related topic:

We have a modular application architecture, built on C# mixins (you might remember our lang.net talk)

Now we need scripting for this app (workflow conditions, document properties and stuff). Of course, we’d like to use DLR hosting for this.

But here’s the catch: Our mixin implementation uses explicit interface implementations to add functionality to existing types via subclass proxies. In a scripting environment however, I’d like to address those “mixed” members just by name.

Which leads us right to the topic of name conflicts.

Our take is that as long as we don’t have name conflicts, we should be able to use the simple name for any member.

However, consider this scenario:

  • There is a type T in Component t
  • Mixin M in Component m adds a member Foo to T
  • A script S in component s refers to Foo using this (pseudo-)code:

T myT; myT.Foo();

Works fine.

Now we add another component m2 at deployment time, containing a mixin M2 that adds another Foo member to T.

Now we have a name conflict in s that the author of s could not anticipate. We don’t want to make the app admin edit the scripts either.

Our solution would be to add an explicit list of referenced components to s, so that name resolution in the context of s would not see M2.Foo, and therefore there would be no name conflict.

I believe you blogged once about a similar topic, but couldn’t get Google to find that page for me.

Is there anything in the DLR that helps us accomplish this? Or would we have to implement that language by language?

Thanks, Stefan