Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4610

Manipulating Output from an Array of Nested Hashes in Ruby

$
0
0

I've been pulling data from an API in JSON, and am currently stumbling over an elmementary problem

The data is on companies, like Google and Facebook, and is in an array or hashes, like so:

[  {"id"=>"1", "properties"=>{"name"=>"Google", "stock_symbol"=>GOOG, "primary_role"=>"company"}},  {"id"=>"2", "properties"=>{"name"=>"Facebook", "stock_symbol"=>FB, "primary_role"=>"company"}}]

Below are two operations I'd like to try:

  1. For each company, print out the name, ID, and the stock symbol (i.e. "Google - 1 - GOOG" and "Facebook - 2 - FB")
  2. Remove "primary role" key/value from Google and Facebook
  3. Assign a new "industry" key/value for Google and Facebook

Any ideas?

Am a beginner in Ruby, but running into issues with some functions / methods (e.g. undefined method) for arrays and hashes as this looks to be an array OF hashes

Thank you!


Viewing all articles
Browse latest Browse all 4610

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>