(Determine in 1 minute) About the proper use of empty ?, blank? And present?

(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.

When using empty?

** 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.

When using blank?

** 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

When using present?

** 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

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

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

(Determine in 1 minute) About the proper use of empty ?, blank? And present?
Proper use of redirect_to and render
Proper use of Mockito and PowerMock
[Java8] Proper use of Comparable and Comparator in terms of employee sorting
About the operation of next () and nextLine ()
Proper use of interface and abstract class
[Ruby basics] About the role of true and break in the while statement
Think about the combination of Servlet and Ajax
Be careful about upgrade if you use | etc. in the URL of Tomcat
Criteria for proper use of render and redirect_to
About next () and nextLine () of the Scanner class
Do you use the for statement after all? Do you use a while statement? Proper use of for statement and while statement
Use of Japanese fonts and external characters in JasperReport
[Grails] About the setting area and the setting items of application.yml
About the problem of deadlock in parallel processing in gem'sprockets' 4.0
About the difference between classes and instances in Ruby
Until the use of Spring Data and JPA Part 2
Until the use of Spring Data and JPA Part 1
[Technical memo] About the advantages and disadvantages of Ruby
Use of Abstract Class and Interface properly in Java
Handling of date and time in Ruby. Use Date and Time properly.
It is difficult to use the empty string or date of DBUnit, so fix it and use it.
Think about the differences between functions and methods (in Java)
Create more Tabs and Fragments in the Fragment of BottomNavigationView
[Java] I thought about the merits and uses of "interface"
About the handling of Null
About the description of Docker-compose.yml
About the same and equivalent
[Java] Get the dates of the past Monday and Sunday in order
Let's consider the meaning of "stream" and "collect" in Java's Stream API.
Spring validation was important in the order of Form and BindingResult