Skip to content

Instantly share code, notes, and snippets.

@Iainmon
Created August 9, 2019 03:19
Show Gist options
  • Select an option

  • Save Iainmon/25b3c3b6520e779f716bfe3eaa976dc2 to your computer and use it in GitHub Desktop.

Select an option

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.
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