I have data in the following format
"stats": {
"team": [],
"outcome": [],
"rank": []
}
I need to determine if there is a combination of 2 or more results present from the above structure then print something.
So the idea is:
(if stats.team.present? && if stats.outcome.present) || (if stats.outcome.present? && if stats.rank.present) || (if stats.team.present? && if stats.rank.present)
A better way is to create a method to add a counter that its incremented if the team, outcome, rank has a count of greater than 0.
And then check if the counter is greater than 2. Eg:
def my_count
count = 0
count += 1 if stats.team.count > 0
count += 1 if stats.outcome.count > 0
count += 1 if stats.rank.count > 0
if count > 1
return true
end
end
Are these the only 2 options or is there a cleaner way?
++operator in Ruby.