Skip to content

Instantly share code, notes, and snippets.

@dncrht
Created August 2, 2013 10:35
Show Gist options
  • Save dncrht/6138975 to your computer and use it in GitHub Desktop.
Save dncrht/6138975 to your computer and use it in GitHub Desktop.
Lightweight OpenStruct implementation (it preserves method cache)
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