enum Direction { North, South, East, West, Up, Down Direction getOpposite() { values()[ordinal() + ordinal() % 2 * -2 + 1] } } Direction.values().each { println "opposite of $it is $it.opposite" }
Standard input is empty
opposite of North is South opposite of South is North opposite of East is West opposite of West is East opposite of Up is Down opposite of Down is Up