You need to check the documentation for each case.
Ruby check nil or empty string.
Well nil is a special ruby object used to represent an empty or default value.
Neither is something that is false nil.
True true false false nil false 0 true abc true.
Anything can potentially be nil and every object can answer to the nil method.
The source of the empty.
Returns nil if the instance was nil and nonzero.
That means that an empty string is not nil and an empty array is not nil.
An object is blank if it s false empty or a whitespace string.
Rails adds the method blank.
You can think of nil as the most general way of representing absence in ruby.
An empty string is one that is not nil it is a string right and has no bytes nothing.
To the object class.
Returned nil or a string or a number something different than true or false.
Any string length 0 anyway using that code inside an else if is a bit verbose i would encourage you to define the present.
Will only return true if the object itself is nil.
If the number was 0.
Everything can be nil but only collections can be empty.
Method is analogous to the following.
Class string def present.
From ruby 2 3 0 onward you can combine the safe navigation operator with numeric nonzero.
Now let s cover a much more specific way of representing a lack of data and that is emptiness.
Is a method some objects respond to.
Method inside the string class.
Is a string class method in ruby which is used to check whether the string length is zero or not.
This is useful in case empty.
That way the returned value is always converted to a boolean value.
For example nil and are blank.