13 Nov '12, 3am

That completely insane flat_map behavior is "not a bug" according to Ruby core.

Issue #3525 has been updated by Yusuke Endoh. Status changed from Open to Rejected Hi, 2010/7/3 Jan Lelis <[email protected]>: > the new flat_map method does not return flatted enumerables: > > irb(main):072:0> [[1,2],2,3].flat_map{|e|e} > => [1, 2, 2, 3] > irb(main):071:0> [[1,2],2,3].flat_map.to_a > => [[1, 2], 2, 3] It is indeed confusing a little, but not a bug. Enumerable#flat_map aggregates values that is returned from block call, and returns a flattend array of these values. Enumerator#to_a aggregates arguments that is passed to (implicit) block and just returns it as an array. Look and consider the result of [[1,2],2,3].reject.to_a. -- Yusuke Endoh <[email protected]> ---------------------------------------- http://redmine.ruby-lang.org/issues/show/3525

Full article: http://www.ruby-forum.com/topic/212511

Tweets

@avibryant @chadfowler is this what you are tal...

apidock.com 23 Nov '12, 10pm

Returns a new array with the concatenated results of running block once for every element in enum . If no block is given, ...