Although it works, the resulting Ruby code is still not expressive enough.
What would a declarative version look like?