(Note) Explanation I have summarized it so that it can be used immediately with the minimum explanation. (Conclusion) If you remember either blank? Or prresent ?, you can do something about it.
** Used when you want to know if the contents are empty after satisfying the following conditions. ** ** ① There must be a container ② The contents are not numbers or true or false
if box.empty?
If ①② is not satisfied, NoMethodError will occur.
** Used when you want to know if the contents are empty or exist in the first place **
irb(main):001:0> box = nil
=> nil
irb(main):002:0> box.blank?
=> true
** Used when you want to know that it exists and the contents are not empty (synonymous with! Blank?) **
irb(main):006:0> box = nil
=> nil
irb(main):007:0> box.present?
=> false
https://qiita.com/go_d_eye_0505/items/541110cb9821734b0623
It was easy to understand because it covers the patterns in a tabular format.
Recommended Posts