Last active
December 30, 2015 00:59
-
-
Save ivanyv/7753638 to your computer and use it in GitHub Desktop.
Crazy global variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'singleton' | |
class G | |
include Singleton | |
attr_accessor :variables | |
def self.[](var) | |
variables[var] | |
end | |
def self.[]=(var, value) | |
variables[var] = value | |
end | |
private | |
def self.variables | |
instance.variables ||= {} | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'globals' | |
G[:wat] = 'that' | |
G[:wat] # == 'that' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got carried away improving and refactoring this useless "feature" :D