aboutsummaryrefslogtreecommitdiff
path: root/examples/37-struct-methods
diff options
context:
space:
mode:
Diffstat (limited to 'examples/37-struct-methods')
-rw-r--r--examples/37-struct-methods/shed-examples.json59
-rw-r--r--examples/37-struct-methods/shed.json58
-rw-r--r--examples/37-struct-methods/src/HelloWorld.shed17
3 files changed, 34 insertions, 0 deletions
diff --git a/examples/37-struct-methods/shed-examples.json5 b/examples/37-struct-methods/shed-examples.json5
new file mode 100644
index 00000000..95fb0a97
--- /dev/null
+++ b/examples/37-struct-methods/shed-examples.json5
@@ -0,0 +1,9 @@
+{
+ examples: [
+ {
+ project: ".",
+ bin: "hello-world",
+ expectedOutput: "one\ntwo\nmany",
+ },
+ ],
+}
diff --git a/examples/37-struct-methods/shed.json5 b/examples/37-struct-methods/shed.json5
new file mode 100644
index 00000000..a6c8e563
--- /dev/null
+++ b/examples/37-struct-methods/shed.json5
@@ -0,0 +1,8 @@
+{
+ bins: [
+ {
+ name: "hello-world",
+ mainNamespace: "HelloWorld",
+ },
+ ],
+}
diff --git a/examples/37-struct-methods/src/HelloWorld.shed b/examples/37-struct-methods/src/HelloWorld.shed
new file mode 100644
index 00000000..cfba064d
--- /dev/null
+++ b/examples/37-struct-methods/src/HelloWorld.shed
@@ -0,0 +1,17 @@
+pub fun main() ! Io -> Unit {
+ print!(Count(1).message());
+ print!(Count(2).message());
+ print!(Count(3).message());
+}
+
+struct Count(value: Int) {
+ fun message(this) -> String {
+ if (this.value == 1) {
+ "one\n"
+ } else if (this.value == 2) {
+ "two\n"
+ } else {
+ "many\n"
+ }
+ }
+}