How to read values dynamically

R

Rupa Ruby

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
 
P

Phrogz

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.
 
R

Rupa Ruby

Gavin said:
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.
 
7

7stud --

Rupa said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,264
Messages
2,571,323
Members
48,007
Latest member
Elvis60357

Latest Threads

Top