Skip to content

Instantly share code, notes, and snippets.

@cscorley
Last active March 9, 2022 04:32
Show Gist options
  • Save cscorley/6ce32318be655f691bed2ebe5242cbb2 to your computer and use it in GitHub Desktop.
Save cscorley/6ce32318be655f691bed2ebe5242cbb2 to your computer and use it in GitHub Desktop.
class Test
def thing
@thing ||= "Hi"
end
def thing=(new_thing)
@thing = new_thing
end
def do_stuff
puts thing
if false
thing = "Huh!"
end
puts thing || "Why nil?"
end
end
t = Test.new
t.do_stuff
class Test
attr_accessor :thing
def do_stuff
puts thing
if false
thing = "Huh!"
end
puts thing || "Why nil?"
end
end
t = Test.new
t.thing = "hi"
t.do_stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment