Forum: IronRuby hash#flatten not implemented

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ccabb5c41e9b0160079a9aef6bd30ff0?d=identicon&s=25 Eduardo B. (eblumenfeld)
on 2011-06-14 05:31
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

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 Blumenfeld
This topic is locked and can not be replied to.