Skip to content

Instantly share code, notes, and snippets.

@rayway30419
Last active March 1, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayway30419/2c0fe56aeb38321795e7ab03c9f38b9a to your computer and use it in GitHub Desktop.
Save rayway30419/2c0fe56aeb38321795e7ab03c9f38b9a to your computer and use it in GitHub Desktop.
Hash#default_proc
videos = Hash.new do |h,k|
h[k] = "https://www.youtube.com/watch?v=#{k.to_s}"
end
%w(vVyf_TqWVzI cZFPVAOrdXQ 5tQ4xHMR3iU).each { |id| videos[id] }
puts videos
# {
# "vVyf_TqWVzI"=>"https://www.youtube.com/watch?v=vVyf_TqWVzI",
# "cZFPVAOrdXQ"=>"https://www.youtube.com/watch?v=cZFPVAOrdXQ",
# "5tQ4xHMR3iU"=>"https://www.youtube.com/watch?v=5tQ4xHMR3iU"
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment