Skip to content

Instantly share code, notes, and snippets.

@davorb
Created October 1, 2012 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davorb/3813267 to your computer and use it in GitHub Desktop.
Save davorb/3813267 to your computer and use it in GitHub Desktop.
class TestClass
def initialize
if defined?(@@app_created)
Window.new
return
end
@@app_created = true
puts "app hasn't been created, so I'll make one"
end
end
class Window
def initialize
puts "the app has been created, so I'll make a window instead"
end
end
TestClass.new # first class
TestClass.new # second class
## output:
# app hasn't been created, so I'll make one
# the app has been created, so I'll make a window instead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment