# Implementing get\_Item in Ruby for access in .NET

**URL:** <https://www.ruby-forum.com/t/implementing-get-item-in-ruby-for-access-in-net/166780>\
**Category:** IronRuby\
**Created:** [April 29, 2009, 2:06pm UTC](https://www.ruby-forum.com/t/implementing-get-item-in-ruby-for-access-in-net/166780 "2009-04-29T14:06:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xerxesb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/da6949/32.png) [@xerxesb](https://www.ruby-forum.com/u/xerxesb)\
**Post date:** [April 29, 2009, 2:06pm UTC](https://www.ruby-forum.com/t/implementing-get-item-in-ruby-for-access-in-net/166780/1 "2009-04-29T14:06:15Z")

</div>

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

```
   @parameter_hash

   def initialize
           @parameter_hash = Hash.new
   end

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

   def [] key
           @parameter_hash[key]
   end

   def get_Item key
           @parameter_hash[key]
   end

```

end

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#?

Thanks,  
Xerx.

---

<div class="post-metadata">

**Author:** ![xerxesb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/da6949/32.png) [@xerxesb](https://www.ruby-forum.com/u/xerxesb)\
**Post date:** [April 29, 2009, 5:39pm UTC](https://www.ruby-forum.com/t/implementing-get-item-in-ruby-for-access-in-net/166780/2 "2009-04-29T17:39:29Z")

</div>

I don’t think there’s any attempt right now to identify an indexer when  
overriding virtual methods. This means that the normal Rubification  
rules kick in and you get

def item key  
end  
def item= key, value  
end

The second of these, of course, isn’t usable from within Ruby – though  
I think it should still work correctly when called by C# through the  
interface.

Obviously, this should be entered as a work item on Codeplex if it isn’t  
there already.
