Question: By definition ruby hashes return nil when a key is not present. But I need to use a custom message in the place of nil. So I'm using something like this:

```
val = h['key'].nil? ? "No element present" : h['key']

```

But this has a serious drawback. If there's a assigned nil against the key this will return "No element present" in that case also.

Is there a way to achieve this flawlessly?

Thanks

Answer: 
you can use the `has_key?` method instead

```
val = h.has_key?('key') ? h['key'] : "No element present"

```
```
val = h.has_key?("key") ? h['key'] : "No element present"

```