This is an activerecord method that exists for any rails object and will return.
Ruby if nil then empty string.
To the object class.
Anything can potentially be nil and every object can answer to the nil method.
Because if discount is nil then it will not have a zero.
In the previous section we ve covered the nil construct in ruby.
This is useful in case empty.
As i said to s can return anything and in general doing things to that string will not affect the underlying object.
Now let s cover a much more specific way of representing a lack of data and that is emptiness.
If you want b to be something other than nil you need to set it.
Same is the case when data false blank.
Because nil is nil not a string.
False nil all blank true present.
Rails adds the method blank.
There is only one nil object with an object id of 4 or 8 in 64 bit ruby this is part of why nil is special.
Well nil is a special ruby object used to represent an empty or default value.
Method to avoid empty string as well.
Nil s to s returns a new string with nil inside it.
Dave newton jul 31 13 at 12 10.
For example nil and are blank.
Is just a double negation of empty.
It s just not worth it.
Returns true for nil false empty or a whitespace string.
So it s better to use blank.
Is a rails method and solves the issue of the ugly error you get when checking if something nil is empty.
I don t understand the issue.
Is an activesupport extension to ruby object and returns true for nil false empty or a white space string.
That way the returned value is always converted to a boolean value.
Current ruby style guide stands the and and or keywords are banned.
Returned nil or a string or a number something different than true or false.
Nil object id 4 let s take.
It s also a falsy value meaning that it behaves like false when used in a conditional statement.