The key is not a scalar. It is an object. The private key is an object of type Crypt::RSA::Key::Private. When you store it do you serialize the object and then unserialize it on retrieval? If not, you are probably not saving and restoring the object itself.
From the error (and checking the code) it seems that you are trying to treat the key as though it were just the raw key value iteslf (a scalar), which it is not.