Skip to content

Instantly share code, notes, and snippets.

@bryanl
Created May 7, 2009 18:26
Show Gist options
  • Select an option

  • Save bryanl/108261 to your computer and use it in GitHub Desktop.

Select an option

Save bryanl/108261 to your computer and use it in GitHub Desktop.
def const_accessor(sym, value, remove=false, freeze=true)
value.deepfreeze if freeze
sym = sym.to_s
down, up = sym.downcase, sym.upcase
sym = up.to_sym
remove_const sym if remove and const_defined? sym
const_set sym, value
class_eval "def #{down}; #{up}; end\ndef self.#{down}; #{up}; end"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment