Repro: https://github.com/sergiocampama/ruby_proto_repro, just run generate_proto.sh from inside the repo.
What happens is that the MessageB gets added to the forward declaration, but its internal enums are not, so the subsequent usage of the enum type fails to be resolved.
One way to fix this particular would be to forward declare all enums, even nested ones, before messages. Then forward declare the messages and finally then extend the messages with any fields that they have defined.