[Ironruby-core] interop question

Ivan Porto Carrero ivan at flanders.co.nz
Tue May 12 03:23:16 EDT 2009


Let's say I have these interfaces

public interface IWeapon{
        void Attack(IWarrior warrior);
        int Damage();
    }

    public interface IWarrior
    {

        int Id { get; }
        string Name { get; set; }
        bool IsKilledBy(IWeapon weapon);
        void Attack(IWarrior target, IWeapon weapon);
    }

And one implementor defined in C#

public class Ninja : IWarrior{

        private readonly int _id;

        public string Name { get; set; }
        public int Id { get { return _id; } }

        public void Attack(IWarrior target, IWeapon weapon){
            weapon.Attack(target);
        }

        public bool IsKilledBy(IWeapon weapon)
        {
            return weapon.Damage() > 3;
        }
    }

Now if I create an implementation of IWeapon in Ruby

class Shuriken

   include IWeapon

   def damage
      2
   end
end

which I then proceed to wrap in a forwarding class

class ShurikenProxy

  instance_methods.each do |name|
      undef_method name unless name =~ /^__|^instance_eval$/
    end

   def initialize
      @subject = Shuriken.new
   end

  def method_missing(m, *a, &b)     @subject.send(m, *a, &b)
  end

end

Then I would expect this to work:

ninja = Ninja.new
ninja.is_killed_by ShurikenProxy.new

only it tells me that the ruby object isn't an implementation of IWeapon
while by all ruby standards it is. if you ask it for its ancestors it's got
IWeapon there
if you ask it for its class it tells you Shuriken and not ShurikenProxy

Is that supposed to happen?


---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Emma Goldman <http://www.brainyquote.com/quotes/authors/e/emma_goldman.html>
- "If voting changed anything, they'd make it illegal."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090512/bcafaa61/attachment.html>


More information about the Ironruby-core mailing list