How to read values dynamically

In ruby, is there any way to read the values from a fileI am actually
giving the values in the code itself. Is there a way to read the value
dynamically

On Sep 12, 12:07 pm, Rupa R. [email protected] wrote:

In ruby, is there any way to read the values from a fileI am actually
giving the values in the code itself. Is there a way to read the value
dynamically

Yes, it is possible. You can either read the file into a string and
parse it to find what you wanted, or you can load the file as ruby
code (if it is) and have the code run.

If that doesn’t answer your question, please provide more details
about what you are trying to do.

Gavin K. wrote:

On Sep 12, 12:07 pm, Rupa R. [email protected] wrote:

In ruby, is there any way to read the values from a fileI am actually
giving the values in the code itself. Is there a way to read the value
dynamically

Yes, it is possible. You can either read the file into a string and
parse it to find what you wanted, or you can load the file as ruby
code (if it is) and have the code run.

If that doesn’t answer your question, please provide more details
about what you are trying to do.

Rupa R. wrote:

In ruby, is there any way to read the values from a fileI am actually
giving the values in the code itself. Is there a way to read the value
dynamically

f = File.new(“aaa.txt”, “w”)
f.puts(10)
f.close

f = File.new(“aaa.txt”, “a”)
f.puts(20)
f.close

arr = IO.readlines(“aaa.txt”)
x = Integer(arr[0])
y = Integer(arr[1])

puts x+y #30