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

  • SEARCH
  • Home
  • 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 8444919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:31:26+00:00 2026-06-10T09:31:26+00:00

Have an array of single pair hashes, like this: arguments = [{:name=>ABCD},{:title=>Awesome},{:number=>4}] I need

  • 0

Have an array of single pair hashes, like this:

arguments = [{:name=>"ABCD"},{:title=>"Awesome"},{:number=>4}]

I need to loop through and pull each one off as a key and value. Right now, I’m doing this:

def methodname(*arguments, &block)
  arguments.each do |arg|
    arg.each do |key, value|
      # use my key and value
    end
  end
  # use the &block here in awesome ways
end

Ick. Gotta be a better way, so I’m asking if someone knows it. I’ve searched and can’t seem to find this particular question on StackOverflow, but let me know if it’s out there.

EDIT: Added context to the code example.

  • 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-10T09:31:28+00:00Added an answer on June 10, 2026 at 9:31 am

    If arguments are expected to be unique…

    arguments.inject({},:merge).each { ... }
    

    FWIW – if you can change this data structure, it might be a good idea to do so. This data is better represented in a single hash.

    You can also define your method differently and avoid the problem altogether.

    irb(main):011:0> def foo(kwargs={},&block)
    irb(main):012:1>    pp kwargs
    irb(main):013:1> end
    irb(main):025:0> foo(:biz=>1,:baz=>2)
    {:biz=>1, :baz=>2}
    => nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array filled with paths looking like this: library/main/single/list.php library/article/grid/thumbs.php library/footer/tiny.php These
I need to display array of images in a single view which have various
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have a multidimensional array that look like this: Array [1] => Array (
If I have an array like this: [0, 1, 2, 3, 4, 5] ,
I have an array with multiple sub-arrays like this: Array ( [0] => Array
Possible Duplicate: Convert multidimensional array into single array I have this array: Array (
I would like to do this with a single function. I have a key=>value
I have an array value like this. My print_r($_POST) looks like this. I can

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.