-
Notifications
You must be signed in to change notification settings - Fork 4
/
enum.rb
47 lines (38 loc) · 989 Bytes
/
enum.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# SPDX-License-Identifier: public domain
class EnumBasic < Contract
# Enum representing shipping status
enum :Status,
:pending,
:shipped,
:accepted,
:rejected,
:canceled
# Default value is the first element listed in
# definition of the type, in this case "Pending"
storage status: Status
# Returns uint
# Pending - 0
# Shipped - 1
# Accepted - 2
# Rejected - 3
# Canceled - 4
sig [], :view, returns: Status
def get
@status
end
# Update status by passing uint into input
sig [Status]
def set( status: )
@status = status
end
# You can update to a specific enum like this
sig []
def cancel
@status = Status.canceled
end
# delete resets the enum to its first value, 0
sig []
def reset
@status = Status.min ## or Status.zero
end
end