Skip to content

Instantly share code, notes, and snippets.

@stevegraham
Created September 20, 2012 00:20
Show Gist options
  • Select an option

  • Save stevegraham/3753194 to your computer and use it in GitHub Desktop.

Select an option

Save stevegraham/3753194 to your computer and use it in GitHub Desktop.
splat
hash = { :name=>"Steve Graham", :age=>24 }
# => { :name=>"Steve Graham", :age=>24 }
array = *hash
# => [[:name, "Steve Graham"], [:age, 24]]
wow = Hash[array]
# => { :name=>"Steve Graham", :age=>24 }
males = %w(pharrell chad shae)
females = %w(cameron jessica alyssa)
justin_timberlake = case gender
when *females "ladies good morning"
when *males "gentlemen goodnite"
when *males|females "hahahahaha and that's it"
end
lines = *File.open('/etc/hosts')
%w(a list of arbitrary words) * ", "
# => "a, list, of, arbitrary, words"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment