This is a personal memo.
――What is a receiver? --Difference between receiver and object --Differences between Ruby and JavaScript objects
The data on the left side of the method is called the receiver.
Receiver.Method
--obj
, obj
of obj.length
--The arr
ofarr.present?
Is called the receiver.
Objects in Ruby are ** all data **. So the following are all objects.
** Object example **
100
"String"
{:a=>1, :b=>2}
[1, 2, 3]
--obj
of obj = {: a => 1,: b => 2}
--arr
ofarr = [1, 2, 3]
--range = 1..3``range
In other words, the receiver is the object ** that is the target of the ** method.
A JS object is data that has properties that are KV (key, value) pairs.
Example: obj = {a: 1, b: 2, c:" xxx "}
In the case of Ruby, all data is called an object.
Objects in JS are hashes in Ruby.
** ▼ Hash (when the key is a character string) ** A string of property names of JS objects.
Example: obj = {"a" => 1, "b" => 2, "c" => "xxx"}
Example: obj = {: a => 1,: b => 2,: c =>" xxx "}
ruby
obj = {a:1, b:2, c:"xxx"}
=> {:a=>1, :b=>2, :c=>"xxx"}