10

Is there a way in Nim to define constructors for an object? For example I have

type Deck* = ref object
    cards* : array[52, Card]

can I create an empty constructor that creates automatically all the cards?

bluenote10
  • 23,414
  • 14
  • 122
  • 178
Mikedev
  • 316
  • 1
  • 8

1 Answers1

10
type
  Card = int
  Deck* = ref object
    cards* : array[52, Card]

proc newDeck: Deck =
  new result
  for i, c in result.cards.mpairs:
    c = i
def-
  • 5,275
  • 20
  • 18