# Hash#flatten not implemented

**URL:** <https://www.ruby-forum.com/t/hash-flatten-not-implemented/208285>\
**Category:** IronRuby\
**Created:** [June 14, 2011, 5:31am UTC](https://www.ruby-forum.com/t/hash-flatten-not-implemented/208285 "2011-06-14T05:31:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 14, 2011, 5:31am UTC](https://www.ruby-forum.com/t/hash-flatten-not-implemented/208285/1 "2011-06-14T05:31:10Z")

</div>

Hi All,

I just found out that Hash#flatten is not implemented in IronRuby, for  
whoever that needs it here is the implementation (I tested it comparing  
the results with Ruby 1.9.2) giving the same results:

* * *

## class Hash def flatten(level=1) a = [] self.each{|x,y| a \<\< x; a \<\< y} while level \> 1 a = a.flatten level -= 1 end a end end

You would need to put it at the very beginning of any application that  
needs that standard functionality.

I’m not sure this is the best implementation, but it is quick & dirty  
and solved my problems with a gem that used Hash#flatten internally…

Hope IronRuby includes the right implementation (or this one if the  
maintainers deem reasonable) in the next IronRuby release.

Best Regards to everyone

Eduardo B.
