[Ruby] Classes, instance variables, instances, etc ...

Progate learning notes What is an instance in a class and an instance variable

class

class Menu
end

Instance variables

class Menu
  attr_accessor :name
  attr_accessor :price
end

Now you can give an instance of the Menu class the information name and price. Please refer to the bottom of the page for easy-to-understand comments about ʻattr_accessor`.

instance

What is born from the class

class Menu
  attr_accessor :name
  attr_accessor :price
end

#An instance called menu1 born from the Menu class
menu1 = Menu.new

#Have information in an instance called menu1
menu1.name = "Bread"
menu1.price = "200"

Reference: Progate

Recommended Posts

[Ruby] Classes, instance variables, instances, etc ...
Organize classes, instances, and instance variables
[Ruby] Classes and instances
Ruby classes and instances
[Ruby] methods, instance methods, etc ...
[Ruby] Basic knowledge of class instance variables, etc.
[Ruby] Class methods, instance methods, etc.
About Ruby classes and instances
Creating Ruby classes and instances
[Ruby] Handle instance variables with instance methods
Memorandum (Ruby: Basic Grammar: Classes and Instances)
Write code using Ruby classes and instances
Classes and instances
Variables / scope (ruby)
About Ruby variables
Ruby: Differences between class methods and instance methods, class variables and instance variables
java classes, instances, objects
Ruby Learning # 29 Classes & Objects
About the difference between classes and instances in Ruby
About Ruby instance methods
Ruby variables and methods
[Ruby] About instance generation
java (classes and instances)
[Ruby] Creating code using the concept of classes and instances
What happens to instance variables when copying an instance with ruby
Ruby classes are constants, not
(Note) Java classes / variables / methods
[Self-use memo] (Ruby) class, class instance, instance
Use ruby variables in javascript.
Difference between variables and instance variables
Instance creation, constructor, field, etc.
[Ruby] What is an instance?
About classes and instances (evolution)
Consideration about classes and instances
Ruby study notes (variables & functions)
[Ruby] Singular methods and singular classes
Ruby variables and functions (methods)
Ruby methods and classes (basic)
About instance variables and attr_ *
[Ruby] Singular methods and singular classes
[Ruby] This is the solution. When should I use instance variables?