[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects

This is a personal memo.

――What is a receiver? --Difference between receiver and object --Differences between Ruby and JavaScript objects

What is a receiver?

The data on the left side of the method is called the receiver.

Receiver.Method

Receiver example

--obj, obj of obj.length --The arr ofarr.present?Is called the receiver.


## Difference between receiver and object

Objects in Ruby are ** all data **. So the following are all objects.

** Object example **

In other words, the receiver is the object ** that is the target of the ** method.


## Differences between Ruby and JavaScript objects This was the most confusing. Object definition is different between JS and Ruby.

For JS

A JS object is data that has properties that are KV (key, value) pairs.

Example: obj = {a: 1, b: 2, c:" xxx "}

For Ruby

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"}


** ▼ Hash (when the key is a symbol) ** A symbol of the property name of a JS object.

Example: obj = {: a => 1,: b => 2,: c =>" xxx "}


If you define `obj = {a: 1, b: 2, c:" xxx "}` like JS, it will be automatically converted to the symbol form.

ruby


obj = {a:1, b:2, c:"xxx"}
=> {:a=>1, :b=>2, :c=>"xxx"}

Recommended Posts

[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects
[Ruby] Difference between get and post
[Ruby] Difference between is_a? And instance_of?
[Ruby] About the difference between 2 dots and 3 dots of range object.
Note: Difference between Ruby "p" and "puts"
Difference between Ruby instance variable and local variable
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
[Ruby] Difference between print, puts and p
Differences between Ruby strings and symbols [Beginner]
[Understanding] Differences between hashes and arrays in Ruby
[Ruby] Difference between puts and return, output and return value
Ruby: Differences between class methods and instance methods, class variables and instance variables
[Java] Difference between "final variable" and "immutable object"
Difference between vh and%
Difference between i ++ and ++ i
[Ruby] I thought about the difference between each_with_index and each.with_index
Differences between Ruby syntax error statements in Ruby and binary
About the difference between classes and instances in Ruby
Difference between product and variant
Difference between redirect_to and render
[Java] Difference between == and equals
Rails: Difference between resources and resources
Difference between puts and print
Difference between redirect_to and render
Difference between CUI and GUI
Difference between variables and instance variables
Difference between mockito-core and mockito-all
Difference between class and instance
Difference between bundle and bundle install
Difference between ArrayList and LinkedList
Difference between render and redirect_to
Difference between List and ArrayList
[Ruby] Difference between match / scan
Differences between IndexOutOfBoundsException and ArrayIndexOutOfBoundsException
Difference between .bashrc and .bash_profile
About Ruby and object model
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
Difference between render and redirect_to
About the difference between "(double quotation)" and "single quotation" in Ruby
The difference between programming with Ruby classes and programming without it
Difference between instance method and class method
Difference between render method and redirect_to
Difference between interface and abstract class
Difference between == operator and equals method
Differences between "beginner" Java and Kotlin
[Java] Difference between Hashmap and HashTable
[Terminal] Difference between irb and pry
JavaServlet: Difference between executeQuery and executeUpdate
Difference between == operator and eqals method
[Ruby] Maybe you don't really understand? [Difference between class and module]
[Ruby] Difference between symbol variables and character string variables. About the difference between [: a] and ['a'].
Rough difference between RSpec and minitest
[Rails] Difference between find and find_by
Understand the difference between each_with_index and each.with_index
Difference between instance variable and class variable
[JAVA] Difference between abstract and interface
Difference between Thymeleaf @RestController and @Controller
Difference between Stream map and flatMap
Differences between Applet class and JApplet class
[Java] Difference between array and ArrayList