[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Slurping an entire file in Windows

List Recv

4/27/2006 3:35:00 PM

A very neat and useful feature of Ruby is:
contents = File.read(filename)

Unfortunately, there's no simple way to do this for *binary* files in
OS's that differentiate (ie Windows). Or is there a similar method
which does the same in binary mode?

A simple workaround is to:
class IO
def self.readbin(filename)
self.class.open(filename, 'rb') { |f| f.read }
end
end

Could I suggest that the maintainers put it in the std-lib?

2 Answers

List Recv

4/27/2006 3:48:00 PM

0

Should be:

class IO
def self.readbin(filename)
self.open(filename, 'rb') { |f| f.read }
end
end

Robert Klemme

4/27/2006 5:18:00 PM

0

listrecv@gmail.com wrote:
> Should be:
>
> class IO
> def self.readbin(filename)
> self.open(filename, 'rb') { |f| f.read }
> end
> end
>
Should be:

class IO
def self.readbin(filename)
open(filename, 'rb') { |f| f.read }
end
end

:-)

robert