You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
asterite edited this page Aug 27, 2011
·
1 revision
In Crystal every method and operator belongs to a type. When you write
1 + 2
Crystal translates it to
1.+(2)
which is pretty similar to what Ruby does.
To define the + method for an Int you write
class Int
def +(other)
# Whatever... can you self and other
end
end
By default, Crystal implements this + for Int as a C call that just adds the two ints without overflow check. Take a look at prelude.cr and crystal.c for this.