LoginSignup
4
2

More than 5 years have passed since last update.

Rubyのよく忘れる演算子一覧メモ

Last updated at Posted at 2017-04-13

概要

Rubyで使われる演算子のうち、よく忘れるものの一覧メモ。
随時追加していきます。

===

状況 動作
左辺が単独のStringやIntegerオブジェクトの場合 ==と同じ動作
左辺がClassオブジェクトの場合: 右辺.is_a(左辺) と同じ
左辺がRegexオブジェクトの場合: 右辺とマッチするかどうかを取れる

引用元:Rubyの===演算子についてまとめてみた

!!

左に!!を付けると、nilの場合でも、falseが返るようになる。

puts !!nil # false
puts !!false # false
puts !!true # true
puts !!'' # true
puts !!0 # true
puts !!1 # true
puts !!'sample' # true

参考

Rubyの===演算子についてまとめてみた
[Ruby]!!(bouble bang)エクスクラメーション2つのRuby演算子について
http://ref.xaio.jp/ruby/classes/module/eqq

4
2
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
4
2