So I assume that the nil returned there may be consistent behaviour. Probably
by nature of the assumption of what is returned, modification in place on
the same object, or a modification what would return a new object.
However had I do agree that, either way, the documentation could be more explicit.
No harm in mentioning that the hash.compact! variant will return nil, which is
what it is presently doing (for an empty hash).
For non-empty hashes as result, it indeed returns the remaining hash, which is
a bit strange, since it may also return a nil ... so people have to check whether
they really have a hash there or just an il:
I do however had also agree that the behaviour may be a bit unexpected... so perhaps
the documentation can be fixed either way and then we can ask whether the behaviour
is the way it should be - but I actually assume that it may be just a documentation
problem.
Oh that's interesting - I hadn't noticed that returning nil if the object was unchanged was the actual behaviour there. I agree it could be seen as a documentation issue - honestly, I'd be happier with the bang method returning the affected object, but so long as the behaviour is expected either way works for me.
This is consistent with many other bang methods. The idea is that the result is available in the changed variable already, and the return value can be used in an if or while expression.
The patch looks good, I hope Nobu can apply it (I can't automatically integrate patches from github).