Best way to slurp a file into a string?

W

Wes Gamble

All,

I would like to capture the entire contents of a file in to a string (a
la Perl) - is this the best way to do it?

File.open(@document.path, r) do |f|
@lines = f.readlines
html = @lines.join
end

so that the html variable has all of the contents of f.

Is there a better/easier way?

Thanks,
Wes
 
D

Daniel Berger

Wes said:
All,

I would like to capture the entire contents of a file in to a string (a
la Perl) - is this the best way to do it?

File.open(@document.path, r) do |f|
@lines = f.readlines
html = @lines.join
end

so that the html variable has all of the contents of f.

Is there a better/easier way?

Thanks,
Wes

IO.read(@document.path)

Regards,

Dan
 
W

Wes Gamble

I see that IO.read takes care of that.

Sorry for the dumb question.

I knew that this would be as easy (or easier) than in Perl!!!

Wes
 
D

Daniel Berger

Wes said:
Isn't it better to do the block thing so that the file gets closed,
etc.?

Nope. No need to worry about that with IO.read. It's not returning an open
handle, just a string.

Regards,

Dan
 
R

Robert Retzbach

Hello,

how can you make a FXLists' frame sunken?
It inherits from FXWindow which has a flag named FRAME_SUNKEN.
But in FXList it has no effect.
I even made a sunken container and put the list in, but that looks horrible!

I appreciate your help.

PS: this I tried:

@leftlist = FXList.new(@secondhframe, nil, 0, LIST_NORMAL |
FRAME_SUNKEN | LAYOUT_FILL_X | LAYOUT_FILL_Y)

@leftlist = FXList.new(@secondhframe, nil, 0, FRAME_SUNKEN |
LAYOUT_FILL_X | LAYOUT_FILL_Y)

@leftlist = FXList.new(@secondhframe, nil, 0, FRAME_SUNKEN)
 
L

Lyle Johnson

how can you make a FXLists' frame sunken?
It inherits from FXWindow which has a flag named FRAME_SUNKEN.
But in FXList it has no effect.
I even made a sunken container and put the list in, but that looks horrib=
le!

Like Yura said, you need to put FXList inside some other container
that is derived from FXFrame. And also, per Yura's code, be sure to
specify zero padding around all four sides of the frame. If you use
the default padding (which IIRC is two pixels on each side) it
probably won't look too nice.
 

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
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top