0
0

More than 1 year has passed since last update.

100日後くらいに個人開発するぞ!day058

Posted at

今日も継承について学んでみた!

image.png

今日の学び

インスタンス変数を用いる際はselfをつける


  • * class Food
    * arttr_accessor :name
    * arttr_accessor :calorie
    * def calorie_info
    * return "#{self.name}は#{self.price}円です"
    * end
    * end

継承されてないインスタンスメソッドを追加する

  • 子クラスに独自のインスタンス変数を追加できたように継承されてないインスタンスメソッドを追加する
      • class Food < Menu
      • arttr_accessor :calorie
      • def calorie_info
      • return "#{self.name}は#{self.price}円です"
      • end
      • end
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