mercredi 20 avril 2016

Random zip method

Is there a way to use the zip method in a random way?

If this is my code

['top', 'left', 'z-index'].zip(['5px', '35px', '10']).each do |attribute, value|
  #not the actual code, just an example
  puts "#{attribute} is #{value}"
end

It will print always in the same order:

top is 5px
left is 35px
z-index is 10

If I shuffle the arrays, then the elements will not match, so maybe it will print

left is 5px

and so on...

What I'd like to achieve is this, as I am using it in my RSpec tests:

FIRST RUN

top is 5px
left is 35px
z-index is 10

SECOND RUN

left is 35px
top is 5px
z-index is 10

etc.




Aucun commentaire:

Enregistrer un commentaire