From: "Jesús Gabriel y Galán" Date: 2009-09-19T06:06:33+09:00 Subject: Re: Array of hashes issue On Fri, Sep 18, 2009 at 10:13 PM, Brad Dude wrote: > I'm new to ruby and am trying to do a project so I can learn ruby and > build a tool I need for my job. Hi, welcome ! > I want to creat an array of hashes and then get the information out. > > This is what I have right now: > > this is in my getIssuesInFileter class: >      @issues = @jira.getIssuesFromFilter(@key) >      @output = Array.new(@issues.length, Hash.new) First thing: I think this is incorrect, because you start with a filled array of length @issues.length, all positions pointing to an empty Hash. Check this: irb(main):001:0> a = Array.new(10, Hash.new) => [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}] irb(main):002:0> a << {:a => 3} => [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {:a=>3}] You see, when I add to the array, I still have 10 positions pointing to an empty hash. Don't think this is what you want. I would do just: @output = [] # or Array.new >      @issues.each { >        |fl| >        @output << {:id => fl.id, :assignee => fl.assignee, :description > => fl.description, :status => fl.status, :type => fl.type, :updated => > fl.updated} >      } > return @output > When things don't go as expected, you can inspect the variables you are dealing with, to see what's going on: > This is where I want to output my results >        issueArray = @JiraClass.getIssuesInFilter(newFilterVal[0]) >      issueArray.each { >        |iss| p iss >        iss.each { >          |issSecD| p issSecD >          puts issSecD[:description], "\n" >        } >      } Adding those two lines should give you a clue of what's going on: iss is one of the hashes in the array. issSecD is an array with each [key,value]. If you are only interested in the description: issueArray = @JiraClass.getIssuesInFilter(newFilterVal[0]) issueArray.each do |issue| puts issue[:description] #puts already prints a "\n". don't know if you actually want 2 of them. end If you want to iterate all of the keys: issueArray = @JiraClass.getIssuesInFilter(newFilterVal[0]) issueArray.each do |issue| issue.each do |key, value| puts "#{key} => #{value}" end Hope this helps, Jesus.