Created
          March 22, 2012 18:40 
        
      - 
      
 - 
        
Save klebervirgilio/2161451 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
klebervirgilio revised this gist
Jul 26, 2012 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,4 +17,8 @@ def by(n) end end [1,2,3,4,5,6].by(2) #=> [[1, 2], [3, 4], [5, 6]] #:P [*0...9].each_slice(3).to_a => [[0, 1, 2], [3, 4, 5], [6, 7, 8]]  - 
        
klebervirgilio revised this gist
Mar 22, 2012 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,11 @@ def by(n) end end # by @mvoto class Array def by(n) self.enum_for(:each_slice, n).to_a end end [1,2,3,4,5,6].by(2) #=> [[1, 2], [3, 4], [5, 6]]  - 
        
klebervirgilio revised this gist
Mar 22, 2012 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ class Array def by(n) buff, self_ = [], self.clone if self.size % n == 0 (self.size/n).times{ buff << self_.shift(n) }  - 
        
klebervirgilio revised this gist
Mar 22, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,10 +4,10 @@ def by(n) self_ = self.clone if self.size % n == 0 (self.size/n).times{ buff << self_.shift(n) } end buff end end  - 
        
klebervirgilio created this gist
Mar 22, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ class Array def by(n) buff = [] self_ = self.clone if self.size % n == 0 (self.size/n).times.map{ buff << self_.shift(n) } end return buff end end [1,2,3,4,5,6].by(2) #=> [[1, 2], [3, 4], [5, 6]]