# Original hash
original_hash = { 'one' => 1, 'two' => 2, 'three' => 3 }
# Transformation using transform_keys method
transformed_hash = original_hash.transform_keys { |key| key.to_sym }
# Output
puts transformed_hash
- Declare an original hash with string keys and integer values.
- Use the
transform_keys
method to transform the keys of the original hash. - Inside the block, use
to_sym
to convert each key from a string to a symbol. - Store the transformed hash in the variable
transformed_hash
. - Print the transformed hash to the console.