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 6698777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:37:05+00:00 2026-05-26T06:37:05+00:00

I am new to ruby and started using it for the last few days,

  • 0

I am new to ruby and started using it for the last few days, so my apologies if I am asking something very basic.

I am looking for a way to convert the following array into a hash.

arr => 

{"id"=>"xxx", "name"=>"show all", "parent_id"=>"yyy", "tsuite_name"=>"show system", "tc_external_id"=>"zzz"}

where arr.length is 1.

I tried to workaround it but could not convert it as a hash.

I needed this because Testlink xmlrpc responds with the format shown above.

Any help on this would be of great help.

Thanks.

  • 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-05-26T06:37:05+00:00Added an answer on May 26, 2026 at 6:37 am

    Welcome to Ruby!

    The below construct is a Hash.

    {"id"=>"xxx", "name"=>"show all", "parent_id"=>"yyy", "tsuite_name"=>"show system", "tc_external_id"=>"zzz"}
    

    If it was an Array, it would be surrounded by braces:

    [{"id"=>"xxx", "name"=>"show all", "parent_id"=>"yyy", "tsuite_name"=>"show system", "tc_external_id"=>"zzz"}]
    

    But what I think you were given was this:

    { "arr" => {"id"=>"xxx", "name"=>"show all", "parent_id"=>"yyy", "tsuite_name"=>"show system", "tc_external_id"=>"zzz"} }
    

    The above object is a Hash within a Hash. The length method reported 1 because the hash only contained a single key, namely, arr.

    You can test the class of a variable with the class method:

    $ irb
    >> var = { "arr" => {"id"=>"xxx", "name"=>"show all" } }
    => { "arr" => {"id"=>"xxx", "name"=>"show all" } }
    >> var.class
    => Hash
    

    If all you need is the value of the inside hash, then grab it like so:

    >> keep = var["arr"]
    => {"id"=>"xxx", "name"=>"show all" }
    

    If I totally misunderstood your question, then please clarify.

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

Sidebar

Related Questions

Rails 2.3.6 started using the fast new json library, yajl-ruby , if available .
I'm very new to Ruby on Rails, and even newer to Haml, i started
I'm new to ruby and started to create my *nd toy app. I: Created
I am very new to Ruby so could you please suggest the best practice
I just started using the new project type SQL Server 2008 Database. I can
I've just started using rails, and decided to follow the Ruby on Rails Tutorial
I'm (extremely) new to Ruby, having started today. I just moved from my system's
I am new to Ruby, using ruby 1.9.2P180 and Rails 3.1.0.rc2 I have screen.css
I started using NoSQL with Ruby. Here's the code I have require 'mongo' require
I am very new to RoR... I installed Ruby and installed its gems... then

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.