AnApprentice AnApprentice - 3 months ago 6x
Ruby Question

How to get items from a ruby hash?

I have the following hash being returned from the Google Drive API:


I'm able to log export links like so:

logger.debug file.export_links

However, I'm unable to get the text/plain url, trying:

logger.debug file.export_links["text/plain"]

This is erroring with
undefined method
[]' for nil:NilClass`.

How can I get the value for text/plain within @export_links?



Are you looking for this? { |k, v| v if k == 'text/plain' }


@export_links.find { |k, _| k == 'text/plain' }

if you need the first match.