Ruby - Variables and Data Types
Given the following code, what will be the output?
hash = { apple: 1, banana: 2 }
key = :apple
hash[key] = 3
puts hash[:apple]Consider the immutability and identity of symbols in your answer.
Given the following code, what will be the output?
hash = { apple: 1, banana: 2 }
key = :apple
hash[key] = 3
puts hash[:apple]Consider the immutability and identity of symbols in your answer.
:apple and key (which is :apple) refer to the same key.hash[key] = 3 updates the value for the :apple key from 1 to 3.puts hash[:apple] prints the updated value 3.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions