Project

General

Profile

Actions

Feature #1880

closed

Hash#flatten Doesn't Operate Recursively for Hash Values

Added by runpaint (Run Paint Run Run) over 15 years ago. Updated almost 13 years ago.

Status:
Rejected
Target version:
[ruby-core:24745]

Description

=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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0