Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
+1 @viniciuscb
Suggestion: email
info@codewars.com
and/or Tweet to@codewars
and@QualifiedIO
, the creators of Codewars.+1 @SimonSwanky
Suggestion: email
info@codewars.com
and/or Tweet to @codewars and @QualifiedIO, the creators of Codewars.This solution received the most votes for "Best Practices." But you and I agree, this monkey-patching of Array and Numeric is not a good practice, let alone "best."
Numeric
andArray
are classes that represent structures of generic data. It is not good practice to add methods to these classes that are only meaningful in a narrow use case.It's correct to say that the problem does not require
five_num
to check for invalid input.This approach changes the interface of Array, adding a new method that throws a
NoMethodError
when the Array instance doesn't conform to a special use case. As a result, any subsequent instance of Array can respond to a method that may be meaningless (and unsafe) for that instance.Why change the interface of Array?
Or to put it another way, would this also be a good solution? Why or why not?
What if an instance of Array contains non-Numeric values?