java 代码
- users_hash = {"tom" => "password0",
- "adi" => "password1",
- "aaron" => "password2" }
- # The following line will not add anything to users_hash.
- # But will return a hash that has users_hash and
- # the new added entry.
- users_hash.merge({"sam1" => "password3"})
- #The following line will modify users_hash by
- #adding the new entry and return it
- users_hash.merge!({"sam2" => "password3"})
- # or you can make it like this
- #users_hash.merge!("sam2" => "password3")
- users_hash.each { |key, value|
- puts "Key is #{key} and value is #{value}"
- }
- cities = [
- {"Name" => "los angeles", "State" => "CA"},
- {"Name" => "las vegas", "State" => "NV"},
- {"Name" => "miami", "State" => "FL"}
- ]
- cities.map! { |c| c.merge!("Count" => 1) }
- puts cities