Created
June 17, 2011 15:11
-
-
Save anewusername1/1031615 to your computer and use it in GitHub Desktop.
Unfickle Blog Post
This file contains 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
class SomeClass | |
SOMECONSTANT = 'somevalue' | |
... | |
end |
This file contains 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
class SomeClass | |
set_const :someconstant, 'somevalue' | |
end |
This file contains 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
> SomeClass::SOMECONSTANT | |
=> 'somevalue' | |
> SomeClass.keys | |
=> [:SOMECONSTANT] |
This file contains 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
gem install unfickle |
This file contains 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
module Unfickle | |
extend Forwardable | |
def set_const(key,value) | |
@hash ||= {} | |
@hash[key.upcase.to_sym]=value | |
end | |
def const_missing(key) | |
@hash[key] | |
end | |
def_delegators :@hash, :each, :values, :keys, :[] | |
def clear | |
@hash = {} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment