From: "marcandre (Marc-Andre Lafortune)" Date: 2012-03-20T02:27:39+09:00 Subject: [ruby-core:43478] [ruby-trunk - Bug #6155] Enumerable::Lazy#flat_map raises an exception when an element does not respond to #each Issue #6155 has been updated by marcandre (Marc-Andre Lafortune). Hi, shugo (Shugo Maeda) wrote: > Why the last example defines to_a? flat_map doesn't call to_a, but to_ary. I think it's to spec that it doesn't call `to_a`. ---------------------------------------- Bug #6155: Enumerable::Lazy#flat_map raises an exception when an element does not respond to #each https://bugs.ruby-lang.org/issues/6155#change-24948 Author: dkubb (Dan Kubb) Status: Closed Priority: Normal Assignee: shugo (Shugo Maeda) Category: core Target version: 2.0.0 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/