LoginSignup
0
0

More than 1 year has passed since last update.

Ruby &=の使い方

Last updated at Posted at 2022-01-10
# +=や*=と同様に考えれば&演算子の意味がわかれば理解できる
foo &= bar
# これは foo = foo & bar を意味する

&演算子

積集合や論理積を意味する

# Arrayの積集合
[1, 1, 2, 3] & [3, 1, 4]
=> [1, 3]

# TrueClass, FalseClass
true & true
=> true

true & false
=> false

false & false
=> false

nil & true
=> false

nil & false
=> false

# Integer(ビット2項演算子)
1 & 1
=> 1

2 & 3
=> 2
0
0
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
0