From: Adam Prescott Date: 2013-05-13T20:23:35+09:00 Subject: Re: Enum#each issue On 13 May 2013 12:16, Love U Ruby wrote: > > so.rb:2:in `each': undefined method `each' for "string":String > (NoMethodError) > from so.rb:2:in `
' > String doesn't have an #each method, as the documentation will point out (and String doesn't include Enumerable or anything). Object#to_enum makes #to_enum available to all String instances, and defaults to the method #each: http://www.ruby-doc.org/core-1.9.3/Object.html#method-i-to_enum Since the Enumerator wrapper around "string" is lazy, there is no error with "string".to_enum, but that doesn't mean String#each doesn't exist. You might look at, for example, #bytes/#each_byte, #chars/#each_char or #lines/#each_line (among others) to iterate over different manifestations of the string's data.