While learning programming, this keeps what you want to make a note of for yourself.
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.
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.
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