From: Yusuke Endoh Date: 2012-02-14T22:35:06+09:00 Subject: [ruby-core:42622] [ruby-trunk - Feature #1880][Rejected] Hash#flatten Doesn't Operate Recursively for Hash Values Issue #1880 has been updated by Yusuke Endoh. Status changed from Assigned to Rejected I'm rejecting this feature ticket because no progress has been made for a long time. See [ruby-core:42391]. I think flatten means an operation on Array, in Ruby. "flatten" on Hash is also possible, but Hash#flatten is not for that. I think we need: - a use case - another appropriate name - detailed semantics (what does {a: {a: 1}}.flatten return?) -- Yusuke Endoh ---------------------------------------- Feature #1880: Hash#flatten Doesn't Operate Recursively for Hash Values https://bugs.ruby-lang.org/issues/1880 Author: Run Paint Run Run Status: Rejected Priority: Normal Assignee: Yukihiro Matsumoto Category: core Target version: 2.0.0 ruby -v: ruby 1.9.2dev (2009-08-04 trunk 24388) [i686-linux] =begin Hash#flatten claims to flatten recursively if given an argument specifying the depth. This works as expected for Array values, but has no bearing on Hash values. >> h = {orange: :orange, coconut: {inside: :white, outside: :brown}, grapes: {colour: [:red, :green]}} >> h.flatten => [:orange, :orange, :coconut, {:inside=>:white, :outside=>:brown}, :grapes, {:colour=>[:red, :green]}] >> h.flatten(20) => [:orange, :orange, :coconut, {:inside=>:white, :outside=>:brown}, :grapes, {:colour=>[:red, :green]}] This seems peculiar. If the user has specified a depth he's explicitly stating the level of recursion to flatten; not how he wants Array values to be treated. IOW, I expected #flatten(depth) to call #flatten on Hash values as appropriate. This can be generalised to: call #flatten on values until the depth has been reached. =end -- http://bugs.ruby-lang.org/