Forum: IronRuby hash#flatten not implemented

C94afbb820c49a847b3b1f5244178f82?d=identicon&s=25 Eduardo Blumenfeld (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.