Versions Compared

Key

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

...

Code Block
def today = Day.SATURDAY
switch (today) {
     // Saturday or Sunday
     case [ Day.SATURDAY, Day.SUNDAY ]:
         println "Weekends are cool"
         break
     // a day between Monday and Friday
     case Day.MONDAY..Day.FRIDAY:
         println "Boring work day"
         break
     default:
         println "Are you sure this is a valid day?"
}

...

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

// another way 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

...