Hash the password and store the hash as a string.
When the user types the password, hash it and compare it to the hashed string. If it matches, it's correct otherwise it's not.
This is secure since you can't get the original password from the hashed string.
This example uses SHA-512, which is secure, since it can't be brute forced (yet).
def is_valid?(password)
hash = Digest::SHA512.hexdigest(password)
mypassword == #the hash of your password
if hash == mypassword
return true
else
return false
end
Edit:
As @Jörg W Mittag suggested, using Argon2 is a better option in terms of security, since it is actually for password hashing.
More info on Argon2:
https://github.com/technion/ruby-argon2
--
What is hashing?
https://en.wikipedia.org/wiki/Hash_function
--
Hashing in ruby:
http://www.informit.com/articles/article.aspx?p=2314083&seqNum=35
https://richonrails.com/articles/hashing-data-in-ruby