Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:41:47+00:00 2026-06-15T16:41:47+00:00

Here is my code snippet: something_1.each do |i| something_2.each do |j| Data.each do |data|

  • 0

Here is my code snippet:

something_1.each do |i|
    something_2.each do |j|
      Data.each do |data|
       date = data.attribute('TIME_PERIOD').text
       value = data.attribute('OBS_VALUE').text
       date_value_hash[date] = value
     end
    end
  end

I want to capture all the values in a single date. date is the key of my hash and it may have multiple values for a single date. How can I accomplish that here? When I am using this line:

date_value_hash[date] = value

values are getting replaced each time the loop iterates. But, I want to accumulate all the values in my date_value_hash for each dates i.e. I want to build the values dynamically.

Currently I am getting this:

{"1990"=>"1", "1994"=>"2", "1998"=>"0"}

But, I want something like this:

{"1990"=>"1,2,3,4,5,6", "1994"=>"1,2,3,4,5,6", "1998"=>"1,2,3,4,5,6"} 

Anyone have any idea how can I accomplish that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:41:48+00:00Added an answer on June 15, 2026 at 4:41 pm

    Like this

    magic = Hash.new{|h,k|h[k]=[]}
    magic["1990"] << "A"
    magic["1990"] << "B"
    magic["1994"] << "C"
    magic["1998"] << "D"
    magic["1994"] << "F"
    

    after which magic is

    {"1998"=>["D"], "1994"=>["C", "F"], "1990"=>["A", "B"]}
    

    and if you need the values as comma separated string (as indicated by your sample data), you’ll just access them as

    magic['1990'].join(',')
    

    which yields

    "A,B"
    

    if later you want to pass magic around and preventing it from automagically creating keys, just wrap it as follows

    hash = Hash.new.update(magic)
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
Here is my code snippet where I'am taking confidence with initialization blocks class Father{
I have a class with two constructors (C#). Here is the code snippet: public
I don't know why I'm facing that error ! Here is my code snippet
Here is the following code-snippet I'm using in my Google Spreadsheet onEdit() function: else
here is the relevent code snippet: public static Rand searchCount (int[] x) { int
Here's the relevant code snippet. public static Territory[] assignTerri (Territory[] board, String[] colors) {
I have a small code snippet for deleting element in linked list. Here is
I'm reading a csv file using c# here is a little code snippet. using
this is my code snippet. function customFadeIn () { $(img.imgKit).each(function(index) { $(this).delay(1000*index).fadeIn(slow); }); console.log(one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.