RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Why struct? Not Hash or OpenStruct?

When we want to store the key value pair most of them prefer Hash, because that is how we learned from the basic. But in real time compare to Hash and Openstruct, Struct works better than other key value storage… Find the useful arcticle http://bit.ly/1hWI1aM

Comments

Real time compare to Hash and Openstruct, Struct works better than other key value storage in #ruby.

I’d personally also freeze the response, since a result is presumably immutable.

I think Struct is great for when you know exactly what parameters you’re going to get. For when you don’t, OpenStruct or Hashes (with Indifferent Access) are better, in my opinion. You can also chuck a hash into an OpenStruct and get methods that way.

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in