If I try to access a hash element that isn't present, I get NoMethodError: undefined method '[]' for nil:NilClass
. However, I can't predict which elements will be present.
@param_info = {}
@param_info["drug"]["name"]
# => NoMethodError: undefined method `[]' for nil:NilClass
How can I avoid raising this error when an element is unexpectedly nil
?