Created
August 9, 2019 03:19
-
-
Save Iainmon/25b3c3b6520e779f716bfe3eaa976dc2 to your computer and use it in GitHub Desktop.
An example of how classes are pointers, and structs are by value in Crystal Lang.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| property name : String | |
| def initialize(@name : String); end | |
| end | |
| struct Human | |
| property name : String | |
| def initialize(@name : String); end | |
| end | |
| c1 = Person.new "iain" | |
| c2 = c1 | |
| c2.name = "Iain" | |
| puts c1.name # => Iain | |
| puts c2.name # => Iain | |
| s1 = Human.new "iain" | |
| s2 = s1 | |
| s2.name = "Iain" | |
| puts s1.name # => iain | |
| puts s2.name # => Iain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment