Reputation: 497
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
Upvotes: 0
Views: 999
Reputation: 5721
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.
Upvotes: 0
Reputation: 15284
mail = gets.chomp
gets function gives a string with \n in the end.
Upvotes: 2