More Ruby I/O
/*********************************************** * Image Thumbnail Viewer Script- © Dynamic Drive (www.dynamicdrive.com) * This notice must stay intact for legal use. * Visit http://www.dynamicdrive.com/ for full source code ***********************************************/
Well, not that I/O is very difficult and useful (as in Java or any language (keeping aside C)), but it always gives some kind of hands of knowledge about the language itself, so let us do some simple I/O by reading a file, (keeping in the flow of converting Centigrade to Fahrenheit as before), our program would read centigrade value from a file named “temp.dat” and spit out the converted value.
num = File.read(”z:\\Ruby - Programs\\temp.dat”)
c = num.to_i
f = (c * 9 / 5) + 32
puts(”Centigrade = ” + num)
print(”Result: “,f)
Nothing much going on in there, we simply read the file to get the “num” value (assigns the value to num variable); converts the value and shows the result. So there we go, thats some basic File I/O using Ruby!.
Now that we have a good feel for Ruby (Hopefully, if not you can post questions as comments and i would try to clear them ASAP), we’ll move to the “good” stuff soon enough. (After we get more and more feel for Ruby, We should be good to go for trying out Rails framework
).
Regards
Vyas, Anirudh