ruby - When should I use Struct vs. OpenStruct? -


Normally, what are the advantages and disadvantages of using OpenStruct compared to Stract? What kind of common usage will fit into each of these?

One OpenStruct , you can create properties arbitrarily on the other hand, When you make it, a structure should define its properties. The choice of one should be primarily on the other, whether you should be able to add features later or not.

The way to think about them is in the middle of the spectrum between the hashes and in the form of other sections. They show a more substantial relationship between data than hash , but they do not have such examples, such as a class. Understand a bunch of options for the function, for example, in a hash; They are only loosely related A name, email and phone number required by a function can be packed together in structure or OpenStruct if that name, email and phone number You need to have the necessary methods to name in "First Last" and "Last, First" forms, so you should make a class to handle it.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -