Closed rainchen closed 6 years ago
About the nil value issue, I'm not quite sure how to deal with.
There is "undefined object" pattern for such cases:
UNDEFINED = Object.new.freeze # anonymous object, equal only to itself
def count category=UNDEFINED
return .... if category == UNDEFINED
With this idiom, we know for sure that UNDEFINED
would not be one of the categories in the vector, so, everything works always as expected, even for nil
category.
@zverok good idea
@zverok All checks have passed, plz review
@zverok updated.
About the nil value issue, I'm not quite sure how to deal with. I wish to keep using the same style with
count
method after the vector converted to category type, e.g.:how about using a special
:nil
key for counting nil values? .e.g:vc.count(:nil)