If e
is a Hash
, as one could deduce from the way you show the contents of e
,
you could write
e["fields"][0]["description"]
As usual in Rails there are many ways to achieve the same, and sometimes not.
You could also write e[:fields][0][:description]
but only if the Hash
has indifferent access, which means you can use strings and symbols interchangeably (that is by default, if you create a hash yourself, not the case).
So to explain the line in more detail: e["fields"]
returns an array (of hashes), take the first element: e["fields"][0]
or e["fields"].first
and then get the value for the key description
in the hash.
However, if you created a class that inherited from StandardError
which is what is usually thrown on error, you would most likely have to write something like:
e.fields
which returns the array of fields. To find the first element, we write, again e.fields[0]
or e.fields.first
, and then it depends if the array contains hashes, or objects with a method description
, so it could either be
e.fields[0].description
or
e.fields[0][:description]
(I prefer to write the symbol key, but please remember if your Hash has strings as keys and is not a HashWithIndifferentAccess
you will have to use the string "description"
)