Forum: Ruby Best way to slurp a file into a string?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-22 21:58
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
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Daniel Berger (Guest)
on 2006-03-22 22:04
(Received via mailing list)
Wes Gamble wrote:
> 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
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-22 22:05
Isn't it better to do the block thing so that the file gets closed,
etc.?

Daniel Berger wrote:
> Wes Gamble wrote:
>> 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
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2006-03-22 22:09
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

Wes Gamble wrote:
> Isn't it better to do the block thing so that the file gets closed,
> etc.?
>
> Daniel Berger wrote:
>> Wes Gamble wrote:
>>> 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
F3b7b8756d0c7f71cc7460cc33aefaee?d=identicon&s=25 Daniel Berger (Guest)
on 2006-03-22 22:11
(Received via mailing list)
Wes Gamble wrote:
> 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
2ce7c81002a564e0e4139bc83d21f10a?d=identicon&s=25 unknown (Guest)
on 2006-03-23 21:08
(Received via mailing list)
Personally File.read makes more sense to me than IO.read... But i've
used both.
8aab717743d4f58a4453adb8b6855e1e?d=identicon&s=25 Robert Retzbach (Guest)
on 2006-03-23 21:27
(Received via mailing list)
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)
0276239ca57aee241d4b41379587fa20?d=identicon&s=25 Lyle Johnson (Guest)
on 2006-03-23 23:34
(Received via mailing list)
On 3/23/06, Robert Retzbach <rretzbach@googlemail.com> wrote:

> 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!

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.
This topic is locked and can not be replied to.