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