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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:32:48+00:00 2026-05-27T10:32:48+00:00

Is it possible to get the Unique values of a Hash? Lets say I

  • 0

Is it possible to get the Unique values of a Hash? Lets say I have a hash which one of the keys is “name” Name can come up a couple dozen times, but it will only have lets say 10 variations of itself all unique. What I want to do is be able to take those 10 unique names and build a view based off of them. But in order to roll the view out properly I would need to know those unique names. Im thinking I have to build an array, or another hash or something of the unique names. So I can go over that array with “each” then for each unique if the original hash has a match apply it to that section or block on the view. Hopefully this makes sense to someone. Who can help me out.

val = {
    :status => "successful",
    :service_list => [
        {
            :service_name => "oozie",
            :status => "RUNNING",
            :status_message => "Running Master Service",
            :host => "1"
        },
        {
            :service_name => "single-namenode",
            :status => "RUNNING",
            :status_message => "Running Service",
            :host => "1"
        },
        {
            :service_name => "single-database",
            :status => "RUNNING",
            :status_message => "Running Service",
            :host => "1"
        }
]}

truncated version of the hash I am working with.

  • 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-27T10:32:49+00:00Added an answer on May 27, 2026 at 10:32 am

    Not sure if it is the right answer, but the list of unique service names can be obtained like this:

    val[:service_list].map { |service| service[:service_name] }.uniq
    # ["oozie", "single-namenode", "single-database"]
    

    Update:

    Iterating over the hash of services grouped by service_name is a little easier, here’s an example:

    In the action of your controller:

    @services =  val[:service_list].group_by { |service| service[:service_name] }
    
    # {
    #    "oozie" => [ { ... }, { ... } ],
    #    "single-namenode" => [ { ... }, { ... } ],
    #    "single-database" => [ { ... }, { ... } ]
    # }
    

    In your view

    <% for name, services in @services %>
        All services with name <%= name %>
        <% for service in services %>
            <%= service[:host] %>, Status: <%= service[:status] %>
        <% end %>
    <% end %>
    

    Hope that helps

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

Sidebar

Related Questions

I have table one which looks like this. And I want to get data
Possible Duplicate: Array unique values Get unique results from JSON array using jQuery Im
I have 60 columns and I need to get unique values from all the
Possible Duplicate: Get variable name. javascript “reflection” Is there a way to know the
Possible Duplicate: Get file name from URI string in C# How to extract file
The documentation says nothing about possible return values. I have looked for the implementation
Using MethodBase , is it possible to get the parameters and their values of
In a data frame, I have one column containing character strings. Let's say it
In Oracle, it's possible to get a count of distinct values in multiple columns
Possible Duplicate: How to get last inserted id? I have a table Absences |

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.