You can use the two functions - presence and present to check for presence of a value and perform functions accordingly
What's the difference?
present? will check to see if a value exists and if it is present it will return one value and if not present it will return the second value. Let's look at a few example..
Note: A word on formatting - you should leave a space after the two ??
If you check to see if 's' is present, the result will be true, so you pick the first value "a" and return that.
's'.present? ? "a" : "b"
In this example, there is nothing, so the result will be false, therefore you pick the second value "b" and return that.
''.present? ? "a" : "b"
1.present? ? "a" : "b"
0.present? ? 0 : 1
presence on the other hand, checks to see if the value exists and returns the value if it exists, otherwise it will return nothing
If nothing was there it returns nil