0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

#selfとは
オブジェクトそのもの。メソッドの中では、そのメソッドが属しているインスタンスをselfという名前の擬似変数で参照できる。他の言語でいうthis。
#selfの特徴
メソッドの中で、レシーバを省略したメソッド呼び出しが行われた時は、selfがレシーバとなる。
レシーバは省略できる場合には省略することが多い。
#使い方

class Numbers
  attr_accessor :number
  def set_number
    self.number = 30 #このクラスのnumberを呼んだ時に30を入れておく
  end
end

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

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?