Search code examples
rubyarrayshashsteam-condenser

Confusion with Hashes and Arrays when using steam-condenser Ruby gem


I'm trying to use the steam-condenser gem to pull a list of games for a particular user (myself). So far I have the following:

require 'steam-condenser'

id = SteamId.new 'tamachan87'
games_owned = id.games

games_owned is now a hash, containing keys and arrays.

If I call games_owned.values in IRB I will get a result that contains all the information of those games, from it's ID number to the name to its logo hash.

However, when I use the following:

games_owned.each do |key, array|
    puts "==== #{key} ===="
    puts array
end

I get just the first value of the array such as:

==== 200260 ====
#<SteamGame:0x00000100beb0a8>

Each value/array thing has an @name variable which is the only thing I want to pull.

Could someone please help me to better understand these hashes and how I can pull specific data (@name) from them?

Thanks in advance.


Solution

  • The return value of SteamId#games is not a hash of arrays, it's a hash of SteamGame objects.

    Your example code could be written like that:

    games_owned.each do |app_id, game|
      puts "==== #{app_id} ===="
      puts game.name
    end
    

    See the documentation of SteamId for more information.