Skip to content

Commit

Permalink
Show full program in tutorial with highlighted lines
Browse files Browse the repository at this point in the history
  • Loading branch information
shaedrich authored Jun 5, 2024
1 parent caae6e2 commit e64107a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 24 additions & 9 deletions docs/types/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

Just like other object-oriented languages, Pony has __classes__. A class is declared with the keyword `class`, and it has to have a name that starts with a capital letter, like this:

```pony
--8<-- "classes-wombat.pony:1:1"
```
=== "Snippet"
```pony
--8<-- "classes-wombat.pony:1:1"
```
=== "Full program"
```pony hl_lines="1"
--8<-- "classes-wombat.pony"
```

__Do all types start with a capital letter?__ Yes! And nothing else starts with a capital letter. So when you see a name in Pony code, you will instantly know whether it's a type or not.

Expand All @@ -20,9 +25,14 @@ A class is composed of:

These are just like fields in C structures or fields in classes in C++, C#, Java, Python, Ruby, or basically any language, really. There are three kinds of fields: `var`, `let`, and `embed` fields. A `var` field can be assigned to over and over again, but a `let` field is assigned to in the constructor and never again. Embed fields will be covered in more detail in the documentation on [variables](/expressions/variables.md).

```pony
--8<-- "classes-wombat.pony:1:3"
```
=== "Snippet"
```pony
--8<-- "classes-wombat.pony:1:3"
```
=== "Full program"
```pony hl_lines="1-3"
--8<-- "classes-wombat.pony"
```

Here, a `Wombat` has a `name`, which is a `String`, and a `_hunger_level`, which is a `U64` (an unsigned 64-bit integer).

Expand Down Expand Up @@ -50,9 +60,14 @@ Every constructor has to set every field in an object. If it doesn't, the compil

Sometimes it's convenient to set a field the same way for all constructors.

```pony
--8<-- "classes-wombat.pony:1:12"
```
=== "Snippet"
```pony
--8<-- "classes-wombat.pony:1:12"
```
=== "Full program"
```pony hl_lines="1-12"
--8<-- "classes-wombat.pony"
```

Here, every `Wombat` begins a little bit thirsty, regardless of which constructor is called.

Expand Down
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ markdown_extensions:
- name: mermaid
class: mermaid-experimental
format: !!python/name:pymdownx.superfences.fence_code_format
- pymdownx.tabbed:
alternate_style: true
- pymdownx.snippets:
base_path: ['code-samples']
check_paths: true
Expand Down

0 comments on commit e64107a

Please sign in to comment.