instance_methods etc should not include undef'ed method names; based on a patch from @cremno; fix #2613