Created
February 1, 2011 10:29
-
-
Save iNecas/805679 to your computer and use it in GitHub Desktop.
Difference between Hash.new(arg) and Hash.new(&block)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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