[Ironruby-core] Implementing get_Item in Ruby for access in .NET

Xerxes Battiwalla xerxes at bigpond.net.au
Wed Apr 29 08:05:06 EDT 2009

Hi there.

We're trying to access a ruby implementation of a Hash from .NET but
having trouble getting the following snip to work

require 'Dependencies.dll'
class ParameterList
       include Namespace::IParameterList


       def initialize
               @parameter_hash = Hash.new

       def []= key, value
               @parameter_hash[key] = value

       def [] key

       def get_Item key

and on the .NET side:

public interface IParameterList : IEnumerable
   int Count { get; }
   IParameter this[string name] { get; }
   IParameter this[int index] { get; }
   IEnumerator GetEnumerator();
   event ParameterValueChangedEventHandler OnParameterValueChanged;

When we call it from .NET with the following code (The parameters
object is an instance of the Ruby ParamterList class ):
parameter = parameters["Key"];

The error returned is
NoMethodError: undefined method `get_Item' for #<ParameterList:0x0000104>

Is it possible to have a Ruby object with an indexer which is callable from C#?


More information about the Ironruby-core mailing list