Skip to content

Instantly share code, notes, and snippets.

@Voker57
Created April 1, 2009 15:53
Show Gist options
  • Save Voker57/88753 to your computer and use it in GitHub Desktop.
Save Voker57/88753 to your computer and use it in GitHub Desktop.
class ConstHash < Hash
def []=(name, value)
if has_key? name
raise "Can't rebind #{name}"
else
super name, value
end
end
end
class Const
@@dict = {}
def self.method_missing(name, *args)
if name.to_s =~ /=$/
name = name.to_s.chop!
if !@@dict.has_key?(name)
@@dict[name] = args.first
else
raise "Can't rebind #{name}"
end
else
@@dict[name.to_s]
end
end
end
Const.magic = 23
# Const.magic = 88
const = ConstHash.new
const['wtf'] = 23
const['wtf'] = 88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment