I’ve been using ruby hashes for storing info for quite some time. Hashes are very easy to convert to json and back. The json strings are stored as an attribute of the component instance.
This works pretty good, but I’m wondering if I would be better off using classes instead after reading this post.
A few benefits I can think of are.
- Reduce the chance of misspelling property names.
- Methods on the class could be contained to the class. Such as calculating position.
- Potentially more manageable code base. (shorter methods, and less repetition)
Any thoughts? More pros and cons or tips before I dive into refactoring my code?
I was thinking I would make the initializer take a component instance, then read the json attribute to populate properties.