[Ruby] (Decision in 1 minute) About the use of empty?, blank? and present?

less than 1 minute read

(Memorandum) Explanation It is summarized so that it can be used immediately with a minimum. (Conclusion) If you remember either blank? or prresent?

When using ## empty? ** Used when you want to know if the contents are empty after satisfying the following conditions. ** ① Make sure there is a container ② The contents are not numbers, true or false

  if box.empty?

If the conditions ① and ② are not satisfied, NoMethodError will occur.

When using ## blank? Used when you want to know if the contents are empty or in the first place

 irb(main):001:0> box = nil
=> nil
irb(main):002:0> box.blank?
=> true

When using ## present? Used when you want to know that it exists and is not empty (synonym for !blank?)

irb(main):006:0> box = nil
=> nil
irb(main):007:0> box.present?
=> false

I would like to know a little more, what should I do in this case? When

https://qiita.com/go_d_eye_0505/items/541110cb9821734b0623

It is easy to understand because it covers the patterns in table format.

Tags: ,

Updated: