[Ruby] How to retrieve the contents of a double hash


I will summarize how to retrieve the double hash as a memorandum.


Ruby 2.6.5


For example, suppose you have a variable user_date with multiple hashes inside an array.

user_data = [
    user: {
      profile: {
        name: 'Taro'
    user: {
      profile: {
        name: 'Jiro'
    user: {
      profile: {
        name: 'Saburo'

To get the value of the hash, specify the key corresponding to that value.

hash[Key of the value to get]

In addition, when retrieving specific data from a double hash, specify the [Key of the value to be retrieved] continuously up to the data to be retrieved. Therefore. If you try to output only the names of all users, the description will be as follows.

user_data.each do |user|
  puts user[:user][:profile][:name]

that's all

Recommended Posts

[Ruby] How to retrieve the contents of a double hash
How to retrieve the hash value in an array in Ruby
How to check for the contents of a java fixed-length string
How to find the cause of the Ruby error
Customize how to divide the contents of Recyclerview
[Ruby On Rails] How to search the contents of params using include?
[Ruby] How to find the sum of each digit
[Rails] How to get the contents of strong parameters
About the behavior of ruby Hash # ==
Extraction of "ruby" double hash * Review
[Docker] How to see the contents of Volumes. Start a container with root privileges.
How to change the contents of the jar file without decompressing
[jsoup] How to get the full amount of a document
[Ruby] I want to reverse the order of the hash table
[Ruby] Display the contents of variables
How to get the contents of Map using for statement Memorandum
[chown] How to change the owner of a file or directory
How to add a new hash / array
How to determine the number of parallels
[Ruby] Cut off the contents of twitter-ads
How to sort the List of SelectItem
[ruby] Double hash
Ruby double hash
[Ruby] I want to extract only the value of the hash and only the key
How to find out the Java version of a compiled class file
[Java] How to get to the front of a specific string using the String class
How to solve the local environment construction of Ruby on Rails (MAC)!
How to change the value of a variable at a breakpoint in intelliJ
How to get the absolute path of a directory running in Java
A memorandum to clean up the code Ruby
Make a margin to the left of the TextField
The story of introducing Ajax communication to ruby
Set the time of LocalDateTime to a specific time
How to operate IGV using socket communication, and the story of making a Ruby Gem using that method
I want to var_dump the contents of the intent
Output of how to use the slice method
[Ruby] Code to display the day of the week
How to display the result of form input
[Ruby] How to generate a random alphabet string
How to build the simplest blockchain in Ruby
[Java] How to get the authority of the folder
[Ruby basics] How to use the slice method
[Ruby on Rails] How to make the link destination part of the specified id
How to get the ID of a user authenticated with Firebase in Swift
[Ruby on Rails] Rails tutorial Chapter 14 Summary of how to implement the status feed
[Ruby] Meaning of &. How to avoid the error when the receiver (object) is nil
How to make a unique combination of data in the rails intermediate table
[Ruby on Rails] How to Japaneseize the error message of Form object (ActiveModel)
I managed to get a blank when I brought the contents of Beans to the textarea
[Note] [Beginner] How to write when changing the value of an array element in a Ruby iterative statement
[Java] How to get the URL of the transition source
Count the number of occurrences of a string in Ruby
How to delete / update the list field of OneToMany
List the contents of categories created with Active Hash
How to run the SpringBoot app as a service
How to write Scala from the perspective of Java
[Ruby on Rails] How to change the column name
How to install the root certificate of Centos7 (Cybertrust)
[Java] How to get the maximum value of HashMap
[Rails] How to change the column name of the table
[SwiftUI] How to specify the abbreviated position of Text