What is self

What is self

The object itself. Inside a method, you can refer to the instance to which the method belongs with a pseudo-variable named self. This in other languages.

Features of self

When a method call that omits the receiver is made in the method, self becomes the receiver. The receiver is often omitted when it can be omitted.

How to use

class Numbers
  attr_accessor :number
  def set_number
    self.number = 30 #Put 30 when you call the number of this class
  end
end

num1 = Numbers.new
num1.set_number
num1.number # => 30

Recommended Posts

What is self
What is Ruby's self?
What is Cubby
What is Docker?
What is null? ]
What is java
What is Keycloak
What is maven?
What is Jackson?
What is Docker
What is Jenkins
What is ArgumentMatcher?
What is IM-Juggling?
What is params
What is SLF4J?
What is Facade? ??
What is Java <>?
What is Gradle?
What is POJO
What is Java
What is centOS
What is RubyGem?
What is programming?
What is before_action?
What is Docker
What is Byte?
What is Tomcat
What is Maven Assembly?
What is a constructor?
What is vue cli
What is an interface?
What is hard coding?
What is a stream
What is Ruby's attr_accessor?
What is Java Encapsulation?
What is permission denied?
What is instance control?
What is an initializer?
What is Spring Tools 4
What is an operator?
What is object orientation?
What is Guava's @VisibleForTesting?
What is MVC model?
What is an annotation?
What is Java technology?
What is Java API-java
What is @ (instance variable)?
What is Gradle's Artifact?
What is JPA Auditing?
[Swift] What is dismiss?
[Java] What is flatMap?
What is a Servlet?
What is web development?
[Java] What is JavaBeans?
[Android] What is Context? ??
[Java] What is ArrayList?
[Ruby] What is true?
What is HttpSession session = request.getSession ();
What is docker run -it?
[Memorandum] What is an error?
What is DI (Dependency Injection)