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.

🐣【Ruby入門】色んな演算子を整理してみた

Last updated at Posted at 2023-02-27

時々忘れてしまうので、アウトプットとして記載する:writing_hand:

  • 代入演算子の一覧表
演算子 説明 備考
x = y x に y を代入
x += y x = x + y x に y を加算
x -= y x = x - y x に y を減算
x *= y x = x * y x に y を乗算
x /= y x = x / y x に y を徐算
x %= y x = x % y x に y を徐算(余り)
x **= y x = x ** y x * x * y
x &= y x = x & y
x |= y x = x | y ※「|」は本来では半角
x ^= y x = x ^ y
x <<= y x = x << y
x >>= y x = x >> y
x &&= y x && (x = y)
x ||= y x || (x = y) ※「|」は本来では半角
  • 論理演算子の応用
    • hoge = var || "Ruby"
      • var が nil または false でなければ var 代入。そうでなければ、 Ruby 代入
  • 範囲演算子
    • .....の違い
      • ..は、範囲の開始から終了まで(puts (1..3).to_a # => 1 2 3
      • ...は、範囲の開始から終了の1つ手前まで(puts (1...3).to_a # => 1 2
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?