Feature #12734
closed
Added by sos4nt (Stefan Schüßler) over 7 years ago.
Updated over 7 years ago.
Description
It might be useful to have a method that determines whether an array is flat, i.e. one-dimensional.
[1, 2, 3].flat? #=> true
[1, [2, 3]].flat? #=> false
The result should be equivalent to ary == ary.flatten
(without the overhead of actually flattening the array)
- Status changed from Open to Feedback
Please explain the use-case.
It doesn't seem useful to me.
This is pretty trivial to implement yourself:
class Array
def flat?
none?{|e|e.is_a?(Array)}
end
end
[1,2,3].flat?
=> true
[1,[2,3]].flat?
=> false
I have to agree with Nobuyoshi Nakada that I don't really see the use case here.
Herwin W wrote:
This is pretty trivial to implement yourself:
Oh, you're right. I didn't realize that this is merely a type check.
May someone close this feature request?
- Status changed from Feedback to Closed
OK, closing as per request.
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0