Get string from file and save it as variable's definition?

require ‘qwikcrypt’ #This is not important, just a encryption gem

password = gets.chomp
encrypted_password = Qwikcrypt::encrypt(content:) #Encrypting the data
:stuck_out_tongue:
Dir.chdir ‘/my/secret/dir’
save = File.open(“secret.txt”)
save.puts("#{password}")
save = File.close

=begin
Next time the program is opened
The following code may not exist
I’m just making it up for you to understand
=end

print "password: "
password = gets.chomp
encrypted = Qwikcrypt::encrypt(content: password)
check = File.open(“secret.txt”) and save string the file contains to
enpass
if password == enpass
puts “success!”
else puts “Username or password do not match!”
end

Help?

Did you try to run this code at all?

“save = File.close” throws an exception, as the File class has no
‘close’ method obviously. You meant “save.close”.

Why not specify the problem with human words?

Földes László wrote in post #1136764:

Did you try to run this code at all?
No, as you can see on the comment I wrote “The following code may not
exist.”

“save = File.close” throws an exception, as the File class has no
‘close’ method obviously. You meant “save.close”.
I actually know that, It was a mistake. Nevertheless it doesn’t answer
my question.

Why not specify the problem with human words?
I’m not sure about that.

There isn’t any problem. I just want to know a way to get string from a
file and save it as a variable’s definition.

Example:
#secret.txt contains hello, world!
Dir.chdir ‘path/to/secret.txt’
x = File.open(“secret.txt”)
get string from secret.txt #Turn this into ruby code
save the string to lol #Same goes with this
puts lol

Output:
hello, world!

Am 15.02.2014 23:03, schrieb cynic limbu:

get string from secret.txt #Turn this into ruby code
save the string to lol #Same goes with this
puts lol

Output:
hello, world!

content = File.read(‘tip.txt’)
puts content

Output:
This question can easily be answered by searching for
e.g. “ruby read string from file” or similar.

Regards,
Marcus

cynic limbu wrote in post #1136804:

Földes László wrote in post #1136764:

Did you try to run this code at all?
No, as you can see on the comment I wrote “The following code may not
exist.”

I took “The following code” literally. This code is in the “previous”
section.

“save it as a variable’s definition” is complicated, it is simpler to
write “read it into a variable” (this is better for Google)

Output:
This question can easily be answered by searching for
e.g. “ruby read string from file” or similar.

Thanks.

I found it right before receiving your answer.