-3
[:sha,"string"]
[:node_id,"dsd"]
[:stats,{:total=>122},:additions=>23],:deletions=>72}]
[:files,[{:sha=>"456"},:filename=>"456"],{:sha=>"123"},:filename=>"123"]]

I want to access the content of files sha and stats.


  client.commit("healtheintent/hcc_reference_service","3a3c56babbc1c77323d178303fa06f8d11e1133d").each do |key,value|

    if("#{key}"=="files")
      puts ("#{value}")
    end
  end

Now the values returns the entire content inside the files Similarily, How do I access the stats

mechnicov
  • 12,025
  • 4
  • 33
  • 56
C-mmon
  • 43
  • 7

1 Answers1

1

How to iterate over the hash in general

hash = { a: 1, b: 2, c: 2 }

hash.each do |key, value|
  if key == :a
    puts "a is #{value}"
  else
    puts "It is not a, it's #{key}"
  end
end

Also you can iterate over the keys only or over the values only using each_key or each_value methods

mechnicov
  • 12,025
  • 4
  • 33
  • 56