Created
September 10, 2010 09:33
-
-
Save liwh/573376 to your computer and use it in GitHub Desktop.
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
//Hash to Struct | |
class Hash | |
def to_struct(struct_name) | |
Struct.new(struct_name,*keys).new(*values) | |
end | |
end | |
if $0 == __FILE__ | |
h = {:name=>"Dan","age"=>33,"rank"=>"SrA","grade"=>"E4"} | |
s = h.to_struct("Foo") | |
puts "name: " + s.name | |
puts "age: " + s.age.to_s | |
puts "rank: " + s.rank | |
puts "grade: " + s.grade | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment