Regarding writing this in a Puppet function: not me, because I'm
clearly not a Ruby guy, but please feel free to do so if you want to.
That said, I think this should still remain in as it will take a while
for any such function to become broadly available on user's systems.

Like the comment explains, I think the real solution here would be for
facter to grow additional built-in facts, named netmask_cidr and
netmask_cidr_<interface>.