Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
enum Coin {
    penny(1), nickel(5), dime(10), quarter(25)
    Coin(int value) { this.value = value }
    private final int value
    public int value() { return value }
}

assert Coin.values().size() == 4

def pocketMoney = 2 * Coin.quarter.value() + 5 * Coin.dime.value()
assert pocketMoney == 100

// otheranother waysway to do above
def coins = [Coin.quarter] * 2 + [Coin.dime] * 5
println coins // => [quarter, quarter, dime, dime, dime, dime, dime]
println coins.sum{ it.value() } // => 100

...