Aaron Van Bokhoven / aaronvb

I am a Software Developer and a Portrait Film Photographer.
  • I love coding with Ruby and Ruby on Rails, and I love shooting with film.
  • I currently live in Honolulu, Hawaii, but frequent Chicago and California.
  • I believe that programming is a form of art, like painting and photography, where you can express your ideas and logic and see it transform into something real.
Aaron Van Bokhoven
photo: kipkeston
Email me at bokhoven@gmail.com. View my Photography Portfolio. Follow me on Twitter and on Tumblr.

Jul 12, 2010
You're viewing an article, go back to the home page to see more.

I've been working on a class that's pulling information from an API and wanted to create dynamic attributes from a hash(json).

I came across this link:

http://pullmonkey.com/2008/01/06/convert-a-ruby-hash-into-a-class-object

It works pretty well, but I haven't done much benchmarking. I've read in the past that define_method can be slow and has memory leaks.

Following that post, I read the comments and came across OpenStruct:

http://www.ensta.fr/~diam/ruby/online/ruby-doc-stdlib/libdoc/ostruct/rdoc/classes/OpenStruct.html

I have it working with what I need but there's still more testing to be done. Just thought I would share.



© Aaron Van Bokhoven