# IronRuby and Dictionaries

**URL:** <https://www.ruby-forum.com/t/ironruby-and-dictionaries/119558>\
**Category:** IronRuby\
**Created:** [November 7, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/ironruby-and-dictionaries/119558 "2007-11-07T23:08:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_de\_Icaza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@Miguel\_de\_Icaza](https://www.ruby-forum.com/u/Miguel_de_Icaza)\
**Post date:** [November 7, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/ironruby-and-dictionaries/119558/1 "2007-11-07T23:08:09Z")

</div>

Hello John,

```
First the simple problem: I have been investigating some of the

```

failures in the IronRuby test suite while running on Mono. Some of the  
problems in the tests depend on the order that Dictionary\<\>'s  
GetEnumerator will return the data. But Dictionaries do not have any  
sorting order specified. The order of the results is implementation  
specific, and I bet they also depend on the number of elements in the  
Dictionary as well as the hashcodes of the elements for the order.

```
A simple case of this problem is:

```

module M  
C = 1  
class D  
end  
end  
M.constants.each { |x| puts x }

```
 In this test, when you call M.constants.each sometimes we return

```

D,C and sometimes we return C,D. If the order is important, maybe the  
code should switch to use SortedDictionary instead of using a plain  
Dictionary?

```
 The second problem is with Hash, some of the tests are failing on

```

Mono, again because the code assumes that code will be returned in  
sorted order by the Dictionary, for example consider:

> > > puts ‘Q’ =\> ‘W’, ‘E’ =\> ‘R’, ‘T’ =\> ‘Y’

In IronRuby/Mono this returns: TYERQW  
In IronRuby/.NET this return: QWERTY  
In Ruby this returns; QWERTY

```
 But Ruby and IronRuby seem to disagree on another simple example:

```

> > > puts ‘a’ =\> ‘A’, ‘A’ =\> ‘a’

In IronRuby/.NET this return: aAAa  
In irb this returns: AaaA  
In IronRuby/Mono this returns: aAAa

```
The change here is a bit elaborate than just changing class Hash to

```

derive from SortedDictionary, it is also necessary to proxy this code to  
RubyOps not to the existing Equal method, but to a Compare method that  
can return an int to identify less, equal or bigger.

miguel

---

<div class="post-metadata">

**Author:** ![Miguel\_de\_Icaza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/7cd45c/32.png) [@Miguel\_de\_Icaza](https://www.ruby-forum.com/u/Miguel_de_Icaza)\
**Post date:** [November 8, 2007, 12:05am UTC](https://www.ruby-forum.com/t/ironruby-and-dictionaries/119558/2 "2007-11-08T00:05:34Z")

</div>

My fault. The tests are bad.  
Thanks!

Tomas
