Can anyone offer some guidance on why this works:
self.primary_format == "Single" || self.primary_format == "EP"
But this doesn’t
self.primary_format == "Single" || "EP"
Is there a more concise way of doing this?
I need to perform the following and would like to make it as neat as possible. Based on the above, i’m not confident the below will work properly.
self.release.primary_genre.id == 3 || 6 || 8 || 12 || 18
Many thanks!
EDIT:
I should have pointed out that these are part of an if statement.
In ruby nil and false are considered as
Boolean falsemeans your condition will get failed only if its value is either false or nil.In above statement you are checking that primary_format should be either “Single” or ‘EP’ and if not it will get failed.
In above statement you have two statements
self.primary_format == "Single"and"EP"So your condition get passed when any of these is correct. But as per the ruby any object other than the nil and false is considered as true in Boolean statement.here in this case no matter what value of the
self.primary_formatthe condition always returns trueSo you have to use
include?method of an array