Skip to content

Instantly share code, notes, and snippets.

@iNecas
Created February 1, 2011 10:29
Show Gist options
  • Save iNecas/805679 to your computer and use it in GitHub Desktop.
Save iNecas/805679 to your computer and use it in GitHub Desktop.
Difference between Hash.new(arg) and Hash.new(&block)
hash = Hash.new("") # => {}
hash[1] << "Hello" # => "Hello"
hash[2] # => "Hello"
hash = Hash.new{|h,k| h[k] = ""} # => {}
hash[1] << "Hello" # => "Hello"
hash[2] # => ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment