[RUBY] Handling when calling a key that does not exist in hash

A miscellaneous note of what I learned from the Cherry book. Since ruby's hash only returns nil even if you call a key that does not exist, it is difficult to notice the mistake, so I tried to output an explicit message.

hash = Hash.new('A key that does not exist.')
hash.merge!({key1: :value1})
hash[:key1]
# => :value1
hash[:key2]
# => "This is a non-existent key."


Recommended Posts

Handling when calling a key that does not exist in hash
Guidelines for writing processing when a value exists / does not exist in Java Optional
Processing when an ID that does not exist in the database is entered in the URL
If hash [: a] [: b] [: c] = 0 in Ruby, I want you to extend it recursively even if the key does not exist.
[JPA] Compare table1 and table2 to get and update data that does not exist in table2.
Cause of is not visible when calling a method of another class in java
MockMVC returns 200 even if I make a request to a path that does not exist
Correspondence when Ruby version does not switch in rbenv
A story that did not work when trying to handle events in Notification Center
When a breakpoint is set in IntelliJ IDEA but it does not stop in debugging [Gradle]
Docker does not work when DOCKER_HOST is specified in WSL2
[MQTT / Java] Implemented a class that does MQTT Pub / Sub in Java
What to do when "relation" hibernate_sequence "does not exist" in the ID column of PostgreSQL + JPA
[AWS S3] AWS Access Key Id you provided does not exist in our records error [Rails AWS EC2]
[Gradle] The story that the class file did not exist in the jar file
Disable display when not logged in
eclipse package org.springframework.boot.web.servlet.support does not exist
How to interact with a server that does not crash the app
operator does not exist: handling the error timestamp without time zone ~~ unknown
Sample program that returns the hash value of a file in Java
Ignore parameters that do not exist in the model with ObjectMapper # readValue