I need some feedback on a design problem in RubyCLR.
Here’s the problem in a nutshell: Ruby doesn’t support method overloading. RubyCLR fakes it out by generating a shim that lets you call the union of all overloaded methods defined by the current class and all ancestor classes.
Now, the biggest feature that I’m adding to this next drop of the bridge is class-based inheritance of shims. I want to define a shim on the class that it was defined by (via MemberInfo.DeclaringType property). The goal of this is to let folks (who want to) replace the definition of the method where it was defined, and to let all derived classes automatically inherit that method definition. This, of course, doesn’t work if that method is ever overloaded in derived classes.
For the next drop, I’m going to take a hybrid approach: define the shim on the declaring Ruby class object if that method is never overloaded in derived classes. If it is overloaded in derived classes, I’m going to define the shim on the Ruby class that triggered the const_missing event.
I’d really like some second opinions about this, as this is largely stream of consciousness thinking right now. I’m worried about breaking things in lots of other corner cases that I haven’t considered yet.
Do I really need to go to a full-blown method name mangling approach to implement this feature correctly?
3 archived reader comments
Justin (2006-03-06)
I have one initial thought, that maybe this will be very resource intensive. Are you going to have to search the inheritance hiearchy to determine if a given method is overloaded anywhere “downstream”?
Also, I’m a little confused by what this sentence means: “If it is overloaded in derived classes, I???m going to define the shim on the Ruby class that triggered the
const_missingevent.”Care to elaborate?
John Lam (2006-03-06)
I only search when I create the method. So you pay the cost exactly once.
Regarding your second point, this is the current behavior. So if you did a
list_box.name = ‘bob’, I create the Name shim on the ListBox class (and not the Control class where I believe it was declared).Justin (2006-03-07)
Seems like reasonable behavior to me. If I overload a method on Control, it should show up on any derived class I reference later. But, if I overload it on ListBox, it should only show up on ListBox and children.
You may have a problem down the line if a derived type is loaded in dynamically, after the shim has been created, but that is really an edge case I wouldn’t worry about until you have to.