[Self-use memo] (Ruby) class, class instance, instance

the term

About various variables and method terms. The shortage of scope information will be added later. (I'm tired of organizing and writing in my head ...: joy :) If you have any strange points or points you notice, Sorry to trouble you, but I would appreciate your guidance and suggestions: hand_splayed_tone2:

class A #A class(Normal class)
  @@class_variable = "Class variables"

  # @class_instance_variable = "Class instance variable"
  # =>If declared here, it is considered a "class instance variable" rather than an "instance variable".
  #Same prefix as "instance variable"(@〜)。

  def initialize #Instance method
    @instance_variable = "Instance variables"
    puts "#{@instance_variable} at initialize"
  end

  def hoge #Instance method
    puts "#{@instance_variable} at xxx"
  end

  def self.fuga #Class method(Definition method: Singular method method)
    puts "#{@instance_variable} at yyy"
  end

  class << self #Singularity class
    def fuga #Class method(Definition method: Singular class method)
      puts "#{@instance_variable} at yyy"
    end
  end
end

#It can be accessed from the instance method initialize
instance = A.new # => "Instance variable at initialize" #Instance generation

instance.hoge #Instance method call
#Instance variables can also be used with other instance methods
instance.hoge # => 'Instance variable at xxx'

A.new.hoge #Instance method call(name of the class.new.Instance method name)
A.new.hoge # => 'Instance variable at xxx'

A.fuga #Class method call
#Instance variables from class methods(@〜)Cannot be used
A.fuga # => nil

Reference article

:relaxed: @ mogulla3

Recommended Posts

[Self-use memo] (Ruby) class, class instance, instance
[Ruby] Class methods, instance methods, etc.
Ruby memo
ruby exercise memo VI (hello class)
Class in Ruby
[wip] Ruby memo
[Ruby] Basic knowledge of class instance variables, etc.
Ruby: Differences between class methods and instance methods, class variables and instance variables
ruby basic syntax memo
About Ruby instance methods
[Ruby] About instance generation
[Ruby] methods, instance methods, etc ...
Java memo (standard class) substring
[Ruby] Does self refer to a class or an instance?
Ruby study memo (conditional branching)
Write class inheritance in Ruby
Personal memo Progate Ruby I (2)
Java learning memo (abstract class)
[Ruby] What is an instance?
Difference between class and instance
What are Ruby class methods?
Ruby study memo (recursive function)
Personal memo Progate Ruby I (1)
ruby exercise memo I (puts)
[Ruby ~ Iterative processing ~] Study memo 4
[Ruby] Relationship between parent class and child class. The relationship between a class and an instance.
Easy to understand the difference between Ruby instance method and class method.
Difference between instance method and class method
Ruby design pattern template method pattern memo
[Java] Memo for naming class names
[Ruby] Classes, instance variables, instances, etc ...
Ruby Study Memo (Test Driven Development)
Difference between instance variable and class variable
Ruby on Rails 6.0 environment construction memo
String output method memo in Ruby
[Ruby] Date, Time, Datetime class basics
[Ruby] Handle instance variables with instance methods
[Note] [Beginner] Ruby writing memo (refactoring) 1