Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

choudanu4

1
Posts
1
Following
A member registered Jan 28, 2019

Recent community posts

I tried to use unless operator with side-effects, and I was surprised that it doesn't short circuit.

potato_card: deck.add["card" "potato"] unless deck.cards["potato"]

The above creates a new card regardless of whether a "potato" card exists. I was hoping that the left term would not be evaluated  (a.k.a short-circuits) if the right term was not nil.

Is there a better (more idomatic) way to get this short circuit behavior? This is what I'm currently doing:

potato_card: if deck.cards["potato"] deck.cards["potato"] else deck.add["card" "potato"] end

Thank you!