Validate arguments in Ruby? -


I wonder if anyone should validate that the argument passed to a method is of a certain class.

For example, "first logic needs to be a hash", unless "hash.clash == hash" does not require second argument, then DF type (hash = { }, Valid = []) # Validate to be an array "until the array.class == array # real code expiration

Whether it is smart to do or passes in debates Is it just time and time to validate all of them?

Is there any such situation when you have this extra Safety and circumstances when you will not bother

Share your experiences!

< P> I do not recommend this specific approach, because you fail to adjust those sections that provide hash or array semantics but are not those classes. If you need such recognition, you Are Better Using the response_to? with method method? To implement the word: [], it is worth it.

OpenStruct hash economics and attribute-accessory method words, but condition hash.class == hash . It will act like a hash in practice, though.

To keep it in perspective, even in a non-dynamic language, you do not want to do this; You would like to verify that any object applied to IDictionary & lt; T & gt; Ruby idioms will like that, when necessary, you verify that the law exists, because if this happens, the developer probably intends to work their purpose equally.

You can provide additional discretion with unit tests around the customer code as an alternative to making things non-dynamic.

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -