Skip to content

Commit

Permalink
Explain the disappearing Suit
Browse files Browse the repository at this point in the history
  • Loading branch information
cincodenada committed Sep 16, 2021
1 parent 7146540 commit 170bec0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion chapter-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ test "set enum ordinal value" {
}
```

Functions can be given to enums. These are sometimes called "methods", and act as namespaced functions that can be called with dot syntax. When called from an instance of the enum, these methods are automatically passed that instance as their first argument. Notice below that `Suit.spades.isClubs()` is equivalent to `Suit.isClubs(Suit.spades)`.
Functions can be given to enums. These are sometimes called "methods", and act as namespaced functions that can be called with dot syntax. As a convenience, when called from an instance of the enum these methods are automatically passed that instance as their first argument. Thus, `Suit.spades.isClubs()` is equivalent to `Suit.isClubs(Suit.spades)`. Additionally, when calling a method from the enum, we can shorten the argument to omit the enum name and pass it with just a leading dot, as in the example below.

```zig
const Suit = enum {
Expand Down

0 comments on commit 170bec0

Please sign in to comment.