Why doesn't each_slice work?
问题 I am trying to use the Enumerable#each_slice. It doesn't work on my computer, stating that method is not found. I am running ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] API: http://ruby-doc.org/core/classes/Enumerable.html#M003142 Example: (1..10).each_slice(3) {|a| p a} # I get NoMethodError: undefined method `each_slice' for 1..10:Range What am I doing wrong? 回答1: In ruby 1.8.6 you have to require 'enumerator' (which is part of stdlib and has been merged into core in 1.8.7+