Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Created January 20, 2013 14:03
Show Gist options
  • Save carlzulauf/4578897 to your computer and use it in GitHub Desktop.
Save carlzulauf/4578897 to your computer and use it in GitHub Desktop.
Hash initialized Struct
class HashStruct
def self.new(*args)
Struct.new(*args) do
def initialize(hash)
super( *self.class.members.map{|k| hash[k] } )
end
end
end
end
# Usage:
# Person = HashStruct.new(:name, :age)
# person = Person.new(:age => 33, :name => "Dave")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment