[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: fyi : rexml eruby cache'ing

Austin Ziegler

9/13/2003 4:36:00 AM

On Sat, 13 Sep 2003 11:55:19 +0900, paul vudmaska wrote:
> now, instead, i do this
> $globalFile = File.new('xml/global.xml')
> $global = REXML::Document.new($globalFile)
> $globalFile.close

There are two Ruby idioms that you may prefer to this.

1. File.open with a block:

globalXML = nil
File.open("xml/global.xml") do |f|
globalXML = REXML::Document.new(f)
end

This implicitly closes the file at the end of the block.

2. File.read:

globalXML = REXML::Document.new(File.read("xml/global.xml"))

-austin
P.S. Top posting is the practice of replying before the quoted text. It is
particularly frowned upon when the entire quoted message is included
following the reply.
--
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2003.09.13
* 00.31.58