Explicit interface method implementation not callable


From RubyForge #23494, re-reported here: http://www.ruby-forum.com/topic/189305
C# code:
public interface IFoo
    void Bar();
public class Cls : IFoo
    void IFoo.Bar() { }
Ruby code:
x = App::Cls.new
Closed Feb 28, 2010 at 7:06 AM by jredville
This works great for Explicit interfaces, but it doesn't work for nil.as(C) since a ruby TypedObject proxy isn't really a C. Closing this and re-opening the one related to nil. Specs are written and will be checked in this week.


TomasMatousek wrote Oct 9, 2009 at 10:23 PM

One way how this might be implemented is to use TypedObject { object Value; Type Type; } as a holder that carries the type along with the reference. Then we can get the target interface type in the binder. Kernel#as method could return a TypedObject instance. This would also work for nil.as(C).

TomasMatousek wrote Oct 10, 2009 at 2:48 AM

The basic support for this features is now provided by Kernel#clr_members:
x.clr_member(IFoo, :bar).call
Calls method bar on object foo casted to interface IFoo.

More convenient API could be implemented on top of that in Ruby:
class TypedObject
def initialize(obj, type)
 @obj, @type = obj, type

def method_missing name, *args, &block
@obj.clr_member(@type, name).call(*args, &block)

module Kernel
def as(type)
 TypedObject.new(self, type)


wrote Feb 24, 2010 at 8:10 PM

wrote Feb 24, 2010 at 8:10 PM

wrote Feb 28, 2010 at 7:06 AM

wrote Feb 22, 2013 at 12:40 AM

wrote May 16, 2013 at 12:05 PM