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
:relaxed: @ mogulla3