code_junkie

What is a Ruby equivalent for Python's “zip” builtin?

Nov 12th, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. zip(a, b).all? {|pair| pair[0] === pair[1]}
  2.  
  3. [1,2].zip([3,4]) => [[1,3],[2,4]]
  4.  
  5. a.zip(b).all? {|pair| pair[0] === pair[1]}
  6.  
  7. a.zip(b).all? {|a,b| a === b }
  8.  
  9. a.eql?(b)
  10.  
  11. a = %w[a b c]
  12. b = %w[1 2 3]
  13. c = ['a', 'b', 'c']
  14.  
  15. a.eql?(b) # => false
  16. a.eql?(c) # => true
  17. a.eql?(c.reverse) # => false
  18.  
  19. it "returns true if other has the same length and each pair of corresponding elements are eql" do
  20. a = [1, 2, 3, 4]
  21. b = [1, 2, 3, 4]
  22. a.should eql(b)
  23. [].should eql([])
  24. end
Add Comment
Please, Sign In to add comment