[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to read values dynamically

Rupa Ruby

9/12/2007 6:08:00 PM

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
--
Posted via http://www.ruby-....

3 Answers

Phrogz

9/13/2007 5:34:00 AM

0

On Sep 12, 12:07 pm, Rupa Ruby <anu.re...@gmail.com> 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 Ruby

9/13/2007 7:18:00 PM

0

Gavin Kistner wrote:
> On Sep 12, 12:07 pm, Rupa Ruby <anu.re...@gmail.com> 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.

--
Posted via http://www.ruby-....

7stud 7stud

9/14/2007 8:50:00 AM

0

Rupa Ruby 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
--
Posted via http://www.ruby-....