Skip to content

Instantly share code, notes, and snippets.

@jah2488
Created April 24, 2016 23:50
Show Gist options
  • Save jah2488/f04e1691e3cf8d3ee13cc0e66741e596 to your computer and use it in GitHub Desktop.
Save jah2488/f04e1691e3cf8d3ee13cc0e66741e596 to your computer and use it in GitHub Desktop.
I feel like there is a whole blog post in here.
class Test
def initialize
puts "I've been created"
end
end
module Foo
def self.check
tester
end
def self.tester
@tester ||= Test.new
end
def self.reset
@tester = nil # Will 'empty' the ivar, but not actually 'remove' it from the object.
end
end
Foo.instance_variables #=> []
Foo.check
Foo.instance_variables #=> [:@tester]
Foo.reset
Foo.instance_variables #=> [:@tester]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment