"It's lambing time here in the frozen north (Cumbria UK). The farmers are keen that the gates to the fields remain closed. They have a few different mechanisms to close the gates automatically. These range for springs to heavy stones on chains with various levels of polish and complexity. We came across one I hadn't seen before today and I think I needed to consult with an estate agent or an architect how these were done!"
"The mechanism uses the weight of the steel gate to keep it closed. As the gate is opened the nylon wheel rolls up a slope lifting the gate up on the hinge. Let go of the gate and the wheel rolls down the slope closing the gate. Neat."
Ives, by the way, is actually a designer of build/make kits for kids. You can check out his stuff here.
Here's another clever build, for a fence that allows you to step over it (source unknown):
Lastly, one other DIY way to prevent an animal from escaping a fenced-in area: