Skip to content

Instantly share code, notes, and snippets.

@worace
Last active December 30, 2015 04:39
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 worace/7777422 to your computer and use it in GitHub Desktop.
Save worace/7777422 to your computer and use it in GitHub Desktop.
1.9.3-p448 :014 > class MyClass
1.9.3-p448 :015?> def my_config
1.9.3-p448 :016?> @@my_config ||= nil
1.9.3-p448 :017?> end
1.9.3-p448 :018?> def my_config=(setting)
1.9.3-p448 :019?> @@my_config = setting
1.9.3-p448 :020?> end
1.9.3-p448 :021?> end
1.9.3-p448 :022 > config = MyClass.new
=> #<MyClass:0x007faa21080d40>
1.9.3-p448 :023 > config.my_config
=> nil
1.9.3-p448 :024 > config.my_config = false
=> false
1.9.3-p448 :025 > config.my_config
=> nil
1.9.3-p448 :026 > config.my_config = true
=> true
1.9.3-p448 :027 > config.my_config
=> true
1.9.3-p448 :028 > class MyClass
1.9.3-p448 :029?> def my_config
1.9.3-p448 :030?> defined?(@@my_config) ? @@my_config : nil
1.9.3-p448 :031?> end
1.9.3-p448 :032?> end
1.9.3-p448 :035 > MyClass.remove_class_variable(:@@my_config)
=> true
1.9.3-p448 :036 > config.my_config
=> nil
1.9.3-p448 :037 > config.my_config = false
=> false
1.9.3-p448 :038 > config.my_config
=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment