[RUBY] (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


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 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
About the mechanism of the Web and HTTP
[Ruby basics] About the role of true and break in the while statement
Think about the combination of Servlet and Ajax
About the idea of anonymous classes in Java
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
[For beginners] DI ~ The basics of DI and DI in Spring ~
[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
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.
Determine that the value is a multiple of 〇 in Ruby
[Ruby] Questions and verification about the number of method arguments
About the difference between "(double quotation)" and "single quotation" in Ruby
[Ruby] About the difference between 2 dots and 3 dots of range object.
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"
In order not to confuse the understanding of getters and setters, [Do not use accessors for anything! ]
About the handling of Null
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
I thought about the strategy of introducing Combine in iOS development
[Swift] Determine the constellation from the date of birth entered in the UIDatePicker