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 1 year has passed since last update.

文字列演算子 << の意味

Last updated at Posted at 2022-08-20

たまに出てくるこれ    <<

どういう意味なのか?

<< 演算子といい、
配列で自身の末尾に破壊的に値を追加してくれます。

下の文で確認します。

class Food
  @@foods = [ ]
  def self.input
    puts "料理名を入力してください"
    name = gets.chomp
    puts "カロリーを入力してください"
    calory = gets.to_i

    food = Food.new(name, calory)
    @@foods << food
  end
end

@@foodsfoodの値を追加しています。
わかりやすくいうと、@@foodsfoodnamecaloryの値を追加しているということです。

0
0
2

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?