I was learning ruby and could only understand the hashes and arrays that I often see, but I've finally come to understand it recently, so I summarized it! You can see the difference between hashes and arrays by looking at this! (Perhaps)
What is an array?
name = ["Suzuki","Tanaka","Onishi"]
--Multiple elements are lined up
--Enclosed in []
--Elements are separated by ,
--Subscripts are specified as integers in order from the front (in the above, name (1) =>" Tanaka "
)
Hash is like this
name = { a: "Suzuki",b: "Tanaka",c: "Onishi" }
--Hash is essentially the same as an array
--Enclosed in {}
-** You can specify a key (subscript) other than an integer! ** It may be exhausted (in the above, name [: a] =>" Suzuki "
)
{}
when they are essentially the sameIf the hash is surrounded by []
, it's easy to lose track of what is the attribute and what is the key, so it's the hash that's surrounded by {}
! It seems that it is used to make it easier to understand!
If you know this, it will be easier to distinguish when studying or reading the code!
that's all~