Summary of hashes and symbols in Ruby

Summary of how to write hashes and symbols

As I learned, I found a difference in how to implement hashes, so I will summarize it.


#How to write a string with a key
test{"subject" => "Math" , "score" => 60}
#How to write a symbol with a key
test1{:subject => "Math" , :score => 60}
#How to write a symbol with a key(Abbreviated system)
test2{subject: "Math" , score: 60}

#Each output method
puts test["subject"]
puts test1[:subject]
puts test2[:subject]

When executed, all the same values were output. Every time I learn, I will post it. .. ..

Recommended Posts

Summary of hashes and symbols in Ruby
About Ruby hashes and symbols
[Ruby] Classification and usage of loops in Ruby
Symbols and Destructive Ruby
[Understanding] Differences between hashes and arrays in Ruby
Basic methods of Ruby hashes
Summary of FileInputStream and BufferedInputStream
Judgment of fractions in Ruby
Handling of date and time in Ruby. Use Date and Time properly.
Handling of line beginning and line ending in regular expressions in Ruby
Sorting hashes in a Ruby array
Basics of sending Gmail in Ruby
Implementation of ls command in Ruby
[Ruby] then keyword and case in
Write keys and values in Ruby
[Super Introduction] About Symbols in Ruby
[Webpacker] Summary of how to install Bootstrap and jQuery in Rails 6.0
Ruby arrays, hashes, and symbols are confusing, so I summarized them.
A brief summary of DI and DI containers
Acquisition of article information in ruby ​​scraping
Directory information of DEFAULT_CERT_FILE in Mac ruby 2.0.0
Make bubble sort and selection sort in Ruby
Summary of root classes in various languages
Explanation of Ruby Time and Date objects
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
Comparison of JavaScript objects and Ruby classes
Differences between Ruby strings and symbols [Beginner]
Summary of Java Math.random and import (Calendar)
Discrimination of Enums in Java 7 and above
Sorting AtCoder ABC 111 C hashes to solve in Ruby, Perl and Java
[Ruby basics] About the role of true and break in the while statement
[Ruby] Summary of exception classes that appear in error statements [Meaning of NameError]
Summary of how to select elements in Selenium
[Ruby] Summary of class definitions. Master the basics.
Use hashes well in Ruby to calculate the total amount of an order
[Ruby] Behavior of evaluation of conditional expression in while
[Ruby] Arguments with keywords and default values of arguments
About Ruby symbols
[Java] Personal summary of classes and methods (basic)
Recommendation of Service class in Ruby on Rails
About Ruby Hashes
Ruby Learning # 14 Hashes
Summary of new features added in Deeplearning4J 1.0.0-beta4
Class in Ruby
Put CSV files containing "'" and "" "in MySQL in Ruby 2.3
[Ruby] "Reference to object" and "Contents of variable"
Basics of Ruby
Display SF Symbols in different sizes and colors
Ruby on Rails ~ Basics of MVC and Router ~
Basics of threads and Callable in Java [Beginner]
About Ruby Hashes
Heavy in Ruby! ??
Enumerate subsets of arrays given in Ruby (+ α)
Ruby syntax summary
About Ruby Symbols
Summary of Japan time setting and display method
Ruby and Gem
Toward understanding of map and flatmap in Stream (1)
Just put `clang 12.0.0` in macOS` Catalina` and put `ruby 3.0.0`
Summary of what I learned in Spring Batch
Create a native extension of Ruby in Rust