It comes out while learning Ruby The concept of classes and instances.
I didn't understand what it meant when I first started school, so I will write with an example.
A template for determining common attributes and processing rules that you want to have in a value (data). Since it has no substance, the data cannot be moved by the class alone.
Example) In terms of a car, it corresponds to a "blueprint". What to do with colors and shapes (common attributes) in blueprints, What to do with running, stopping, turning signals, etc. (common processing) Paper on which such things are written. It's just a blueprint, so it won't work without a car (instance).
#Class definition (starts with a capital letter)
class Car
end
Data created based on a class. It has an entity and has common attributes and processes defined in the class.
Example) In terms of a car, it corresponds to a "car". Cars have colors and shapes (common attributes), You can run, stop, turn signals, etc. (common processing). It's a car made from blueprints, so it has substance and of course works.
#Instance generation
class Car
end
taxi = Car.new #Create an instance of Car class with new method and assign it to variable taxi
puts taxi #Output instance
Recommended Posts