Talk:Rosetta Code/Rank languages by popularity: Difference between revisions

ruby
(ruby)
Line 131:
:I don't know, probably it's for Ruby 1.9, but you can try replace <lang ruby>langs.each_slice(50) do</lang> with <lang ruby>langs[0..50].each do</lang> --[[User:Guga360|Guga360]] 22:54, 26 June 2009 (UTC)
::It's 1.8.7. I'll mark the example. The indexing solution didn't work, but I used a computer that has 1.8.7 and it works. Thanks for the suggestion, though. --[[User:Mwn3d|Mwn3d]] 23:18, 26 June 2009 (UTC)
 
:: [[User:Glennj|glennj]] 18:43, 27 June 2009 (UTC) -- Here's what the 1.8.7 docs say about <code>Enumerable#each_slice</code><pre>Iterates the given block for each slice of <n> elements</pre>It could be implemented like<lang ruby>def each_slice(ary, n)
(ary.length/n + 1).times {|i| yield ary[i*n,n]}
end</lang>
Anonymous user