[Ruby] I want to extract only the value of the hash and only the key

While learning programming, this keeps what you want to make a note of for yourself.

I want to retrieve only the hash key

Suppose you have a hash like this:

my_favorite_beef = {miyazaki: "Takachiho beef", shiga: "Omi beef", hyogo: "Kobe beef"}

here,

miyazaki
shiga
hyogo

If you want to output ** key only ** like

puts my_favorite_beef.keys

Enter.

I want to output only the value of the hash

As before, we'll use this hash as an example.

my_favorite_beef = {miyazaki: "Takachiho beef", shiga: "Omi beef", hyogo: "Kobe beef"}

And

Takachiho beef
Omi beef
Kobe beef

If you want to output ** value only ** like

puts my_favorite_beef.values

Enter.

Summary

At the end of the hash you want to retrieve, By entering .keys, ** keys only ** By entering .values, ** values only ** Can be taken out.

Recommended Posts

[Ruby] I want to extract only the value of the hash and only the key
[Ruby] I want to reverse the order of the hash table
[ruby] How to assign a value to a hash by referring to the value and key of another hash
I want to change the value of Attribute in Selenium of Ruby
I want to get the value in Ruby
I want to give edit and delete permissions only to the poster
[Ruby] I want to output only the odd-numbered characters in the character string
I want to output the day of the week
I tried to summarize the key points of gRPC design and development
I want to var_dump the contents of the intent
I want to pass the argument of Annotation and the argument of the calling method to aspect
I want you to use Enum # name () for the Key of SharedPreference
I want to get the value of Cell transparently regardless of CellType (Apache POI)
I want to recursively get the superclass and interface of a certain class
I want to display the name of the poster of the comment
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
[Ruby] I want to make a program that displays today's day of the week!
I tried to summarize the basics of kotlin and java
I want to bring Tomcat to the server and start the application
I want to expand the clickable part of the link_to method
I want to call a method and count the number
How to retrieve the hash value in an array in Ruby
I tried to summarize the basic grammar of Ruby briefly
[Ruby] How to retrieve the contents of a double hash
I want to narrow down the display of docker ps
I want to temporarily disable the swipe gesture of UIPageViewController
Sazae-san's rock-paper-scissors I tried to verify the theoretical value and the measured value of the probability of the same hand 5 consecutive times with Ruby
About the behavior of ruby Hash # ==
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
In Java, I want to trim multiple specified characters from only the beginning and end.
I want to get a list of the contents of a zip file and its uncompressed size
[Ruby] How to get the value by specifying the key. Differences between hashes, symbols and fetch
Ruby memorandum (acquisition of key value)
Regarding hash key and value mapping
If hash [: a] [: b] [: c] = 0 in Ruby, I want you to extend it recursively even if the key does not exist.
Webpack and webpacker I want to tell Ruby people right now
I want to understand the flow of Spring processing request parameters
I want to return to the previous screen with kotlin and java!
The story of Collectors.groupingBy that I want to keep for posterity
Want to know what Ruby n is the power of 2? (Power judgment of 2)
I want to limit the input by narrowing the range of numbers
I tried to summarize the methods of Java String and StringBuilder
[Java] I want to perform distinct with the key in the object
I want to control the default error message of Spring Boot
[Controller] I want to retrieve the numerical value of a specific column from the DB (my memo)
[Spring Boot] I want to add my own property file and get the value with env.getProperty ().
I tried to make a parent class of a value object in Ruby
I want to display the number of orders for today using datetime.
I want to display images with REST Controller of Java and Spring!
[Active Admin] I want to customize the default create and update processing
[Ruby] I want to display posted items in order of newest date
I tried to make full use of the CPU core in Ruby
I want to get the field name of the [Java] field. (Old tale tone)
I translated the grammar of R and Java [Updated from time to time]
I tried to measure and compare the speed of GraalVM with JMH
I want to download a file on the Internet using Ruby and save it locally (with caution)
How to find the cause of the Ruby error
I want to sort by tab delimited by ruby
[RxSwift] I want to deepen my understanding by following the definition of Observable
I want to use arrow notation in Ruby