Created
April 28, 2010 17:54
-
-
Save indirect/382451 to your computer and use it in GitHub Desktop.
structs initialized from a hash
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 Foo < Struct.new(:foo, :bar) | |
def self.from_hash(hash) | |
new(*new.members.map{|a| hash[a] }) if hash | |
end | |
end | |
Foo.from_hash("bar" => "bagels", "foo" => "cream cheese") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment