LoginSignup
2
0

More than 5 years have passed since last update.

defined?の罠

Last updated at Posted at 2017-11-15

たった一行のプログラムにはまったのでメモ

# variable_flagは未定義とする
variable_flag = defined?(variable_flag) ? true : false
puts variable_flag # true
# variable_flagは未定義とする
_variable_flag = defined?(variable_flag) ? true : false
puts _variable_flag # false

defined?で調べる変数の結果の代入先をその変数と同じにすると定義済み(true)結果が返る

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