Issue #6155 has been reported by Dan Kubb.

----------------------------------------
Bug #6155: Enumerable::Lazy#flat_map raises an exception when an element does not respond to #each
https://bugs.ruby-lang.org/issues/6155

Author: Dan Kubb
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 2.0.0dev (2012-03-15 trunk 35028) [x86_64-darwin11.3.0]


The following statement will raise "NoMethodError: undefined method `each' for 1:Fixnum":

  [1, 2, 3].lazy.flat_map { |n| n }.to_a

It appears as if Enumerable::Lazy#flat_map is calling #each on every element, regardless of whether it can work or not.

As a reference, the equivalent statement using Enumerable#flat_map works:

  [1, 2, 3].flat_map { |n| n }.to_a


-- 
http://bugs.ruby-lang.org/