Skip to content

Commit

Permalink
Fix Array#flatten to try and convert values using to_ary
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 10, 2013
1 parent 68f06d1 commit 0f3f947
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 4 additions & 0 deletions corelib/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ def flatten(level = undefined)
for (var i = 0, length = #{self}.length, item; i < length; i++) {
item = #{self}[i];
if (!item._isArray && #{`item`.respond_to?(:to_ary)}) {
item = item.$to_ary();
}
if (item._isArray) {
if (level == null) {
result = result.concat(#{`item`.flatten});
Expand Down
1 change: 0 additions & 1 deletion spec/filters/bugs/array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@

fails "Array#flatten does not call flatten on elements"
fails "Array#flatten raises an ArgumentError on recursive arrays"
fails "Array#flatten flattens any element which responds to #to_ary, using the return value of said method"
fails "Array#flatten with a non-Array object in the Array ignores the return value of #to_ary if it is nil"
fails "Array#flatten with a non-Array object in the Array raises a TypeError if the return value of #to_ary is not an Array"
fails "Array#flatten raises a TypeError when the passed Object can't be converted to an Integer"
Expand Down

0 comments on commit 0f3f947

Please sign in to comment.