Skip to content

Instantly share code, notes, and snippets.

@nanki
Created June 24, 2015 15:50
Show Gist options
  • Save nanki/d60c5230844da5a9b633 to your computer and use it in GitHub Desktop.
Save nanki/d60c5230844da5a9b633 to your computer and use it in GitHub Desktop.
# OK
class A
def a=(a)
@a = a
end
end
# OK
class B
def a=(a);@a = a;end
end
# NG
class C
def a
@a
end
def a=(a);@a = a end
end
# compile error
# class D
# def a=(a);@a = a end
# end
[A, B, C].each do |klass|
a = klass.new
a.a = 2
p a
end
# $ crystal --version
# Crystal 0.7.3 [bf72b07] (Sun Jun 7 16:17:59 UTC 2015)
# $ crystal semicolon.cr
# #<A:0x10f074ea0 @a=2>
# #<B:0x10f074e80 @a=2>
# #<C:0x10f078fe0 @a=nil>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment