1

They both seem to accomplish the same thing. What use cases would require one over the other?

Currently, I'm working on some presenter classes. My first thought was to use OpenStruct, but I can't identify a meaningful difference between using a Hash and an OpenStruct.

1
  • 1
    there's a big performance hit when using OpenStructs - see my answer below Commented Apr 19, 2013 at 0:20

2 Answers 2

4
  1. Object syntax v. hash syntax.

If a method requires an object with certain accessors, then a Hash would not work.

Sign up to request clarification or add additional context in comments.

Comments

1

OpenStructs are sloooooooooow and memory intensive , and don't scale well for large data sets. Creating 1 million OpenStructs is ~100x slower than creating 1 million Hashes.

This has been discussed in detail here:

When should I use Struct vs. OpenStruct?

3 Comments

Hmm, so you recommend sticking to Hashes then? Why do people use Structs/OpenStructs then?
Yes, creating 1 million Openstructs is about 100x slower than creating 1 million Hashes. Please check out the detailed comparison in that question I mentioned.
Wow thanks so much Tilo. I guess OpenStructs is just a strange niche case that is rarely used for very rare circumstances. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.