Created
August 2, 2013 10:35
-
-
Save dncrht/6138975 to your computer and use it in GitHub Desktop.
Lightweight OpenStruct implementation (it preserves method cache)
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
class OpenStruct | |
def initialize(args) | |
args.each_pair do |k,v| | |
instance_variable_set "@#{k}", v | |
end | |
end | |
def method_missing(name, *args) | |
instance_variable_get "@#{name}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment