0
0

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 5 years have passed since last update.

備忘録(Ruby:基礎文法:クラスとインスタンス)

0
Posted at

クラス

値の元となるもので値の共通のルールを定義する
共通のルールを守った上で個別のデータを作ることもできる
クラス名は半角英大文字から始める

class クラス名
  # 変数やメソッドの定義
end

インスタンス

クラスを元にして作られるデータ
クラスとは異なり実態をもつ
インスタンスはクラスが使用できるnewメソッドを実行して生成する

newメソッド

クラスは定義しなくてもnewという特別なメソッドを持っている

例:

class Car

end

fire_truck = Car.new  # Carクラスのインスタンスを生成
puts fire_truck  # インスタンスを出力
0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?