One possible problem was that you were using a class name, RigidBody, as a variable name. That may or may not be valid, but it's not good practice.
The main problem is that you were using mode, rather than object.mode. You were trying to change the mode property of the node to which the script is attached, rather than mode property of the nodes in the array rag.