Skip to content

Instantly share code, notes, and snippets.

@ellcs
Last active April 22, 2020 07:39
Show Gist options
  • Save ellcs/8004712382c45378a0f731e9e830312b to your computer and use it in GitHub Desktop.
Save ellcs/8004712382c45378a0f731e9e830312b to your computer and use it in GitHub Desktop.
Helpful ruby oneliners
# create random groups of people
%w(james bob alice eve tux).shuffle.each_slice(2).to_a
# => [["bob", "eve"], ["alice", "tux"], ["james"]]
# assign random tools to people (tools can be empty)
people = %w(james bob alice eve tux)
tools = %w(hammer chainsaw screwdriver)
people.shuffle.zip(tools)
# => [["alice", "hammer"], ["james", "screwdriver"], ["tux", "chainsaw"], ["bob", nil], ["eve", nil]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment