Ruby classes and instances

Introduction

This will be a memo for learning.

In Ruby, many terms such as "object" and "variable" come out and it is difficult, so I would like to output it in my own way to speed up understanding even little by little. If there are any differences, I would appreciate it if you could comment.

What are classes and instances?

To understand classes and instances, we need to understand the terms "object" and "method".

The explanation is below ...

object

An object is " all data in Ruby ".

For example, characters such as "good morning" are called "character string objects", and numbers such as "123" are called "numeric objects".

Method

The "processing" of an object is called a method. Every Ruby object has a "method". For example, like this

-Character string object-> length method-> count the number of characters -Numeric object-> to_s method-> Convert to integer

The methods that each object type has are different. For example, each person has a different personality.

class

A class is a " collection of common properties and methods ", and this time, we will consider a "car blueprint" as an example. When you make a car, you need a blueprint, but all cars have something in common (such as "accelerating" with the steering wheel and brakes). That is, "let's put together the common parts in a blueprint."

In other words, it is a mechanism that allows you to create a class (blueprint) so that you can use it when making other cars.

instance

An instance is a " object created by inheriting attributes and processing from a class ".

Is it easy to understand an object (car) created based on a class (blueprint)? Since it inherits the minimum necessary parts, it is an advantage that you do not have to make a blueprint such as "There is a handle" from scratch.

Recommended Posts

[Ruby] Classes and instances
Ruby classes and instances
About Ruby classes and instances
Creating Ruby classes and instances
Classes and instances
About classes and instances
java (classes and instances)
Write code using Ruby classes and instances
About classes and instances (evolution)
Consideration about classes and instances
[Ruby] Singular methods and singular classes
Ruby methods and classes (basic)
[Ruby] Singular methods and singular classes
About the difference between classes and instances in Ruby
[Ruby] Classes, instance variables, instances, etc ...
Writing code with classes and instances
Organize classes, instances, and instance variables
Classes and instances Java for beginners
[Ruby] Creating code using the concept of classes and instances
Ruby and Gem
Java programming (classes and instances, main methods)
Comparison of JavaScript objects and Ruby classes
Getting Started with Java_Chapter 8_About Instances and Classes
Symbols and Destructive Ruby
I compared classes and instances with worldly things
java classes, instances, objects
HashMap and HashSet classes
[Ruby] Big Decimal and DECIMAL
Ruby Learning # 29 Classes & Objects
Ruby inheritance and delegation
Ruby variables and methods
List and happy classes
Java classes and instances to understand in the figure
Ruby classes are constants, not
GraphQL Ruby and actual development
[Java] Generics classes and generics methods
Ruby syntax errors and countermeasures
About Ruby hashes and symbols
Ruby C extension and volatile
About Ruby and object model
Ruby variables and functions (methods)
Java abstract methods and classes
[For beginners] Explanation of classes, instances, and statics in Java
The difference between programming with Ruby classes and programming without it
[Ruby] Difference between get and post
[Ruby] present/blank method and postfix if.
[Ruby] Difference between is_a? And instance_of?
Ruby standard input and various methods
About Ruby single quotes and double quotes
How to call classes and methods
[Ruby] then keyword and case in
[Ruby basics] split method and to_s method
About Ruby product operator (&) and sum operator (|)
Write keys and values in Ruby
[Ruby] If and else problems-with operators-
[Ruby] Boolean values ​​and logical operators
Java generics (defines classes and methods)
Project ruby and rails version upgrade
About object-oriented inheritance and about yield Ruby
[Ruby] About variable naming rules. Also naming conventions for constants, classes, and methods.
With ruby ● × Game and Othello (basic review)