0

I take a string variable from a user like this:

mail = gets

and I want to use this variable to open a file.

file = File.new(mail, "r") ##obviously this isn't working

How do I actually use this mail variable to open a file of that name?

Thanks

2 Answers 2

2
mail = gets.chomp

gets function gives a string with \n in the end.

Sign up to request clarification or add additional context in comments.

1 Comment

Worked perfectly, Thanks texasbruce
0

I prefer mail = gets.strip.

strip seems to be slightly slower than chomp but I find it to be a little bit more readable.

If you're curious about the benchmark, check out the gist here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.