I also maintain ruby-build that is multi-platform build wrapper for ruby. I often got build failure
report caused to missing zlib headers. examples are here.
We took a look at this issue at yesterday's developer meeting.
It surprised me that currently, zlib and several other header files are mandatory for building ruby from the source. It might be trivial for developers like us, but not for everyone who try compiling ruby.
The solutions to cover this glitch might include:
Ship zlib along with ruby. This menu has additional choice whether the bundled zlib shall be statically linked or not.
Fetch and compile zlib before building ruby, by the ruby-build script. This one needs to pass the result of zlib detection between ruby and ruby-build.
Either way ext/zlib has to be aware of the situation. The OP's pull request is for that purpose.
And for macOS: try to not mess up your system by installing random stuff in /usr/local, that's the source of many issues reported to ruby-build.
Using Homebrew is fine (or MacPorts), but manually installing stuff in /usr/local is asking for trouble.