Edit Sep.11, 2020: Just changed the description of the magnet I used, the thickness was incorrect: 2.75mm instead of 1mm. Now the magnet thickness can be adjusted in Onshape.
I saw a ruler with an adapter to use it as a square in an online Chinese store (I can't find the link now) and I wanted to design one for a 160 mm ruler I have. The adapter can also be used to make 45 degree lines. I really liked the magnet idea for keeping the pieces together. I would say that the screw is optional, but it helps to keep the ruler aligned to the adapter wall.
My ruler's width is 19.2 mm but this adapter should work with rulers up to 21.1 mm depending on printer's tolerances as it is now. It uses an M4x10 screw to align the ruler and a 8.1 mm diameter magnet (2.75 mm thick) that I had around to keep the adapter and the ruler together.
I designed it in Onshape and it should be customizable for different rulers' width and magnets' diameters. However, I am not an expert designer and this is one of my first attempts to do something customizable. Please ask if you have any question or need support to adapt it to your needs.
Onshape document
Rule_Square_-_Rule_square.stl | 669.8KB |