Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Best way to slurp a file into a string? (http://www.velocityreviews.com/forums/t829816-best-way-to-slurp-a-file-into-a-string.html)

Wes Gamble 03-22-2006 08:58 PM

Best way to slurp a file into a string?
 
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

--
Posted via http://www.ruby-forum.com/.



Daniel Berger 03-22-2006 09:04 PM

Re: Best way to slurp a file into a string?
 
Wes Gamble wrote:
> 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



Wes Gamble 03-22-2006 09:06 PM

Re: Best way to slurp a file into a string?
 
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



--
Posted via http://www.ruby-forum.com/.



Wes Gamble 03-22-2006 09:10 PM

Re: Best way to slurp a file into a string?
 
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



--
Posted via http://www.ruby-forum.com/.



Daniel Berger 03-22-2006 09:11 PM

Re: Best way to slurp a file into a string?
 
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

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

>
>
>





skhisma@gmail.com 03-23-2006 08:05 PM

Re: Best way to slurp a file into a string?
 
Personally File.read makes more sense to me than IO.read... But i've
used both.


Robert Retzbach 03-23-2006 08:27 PM

FXRuby, FXList with (sunken) Frame
 
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)



Lyle Johnson 03-23-2006 10:34 PM

Re: FXRuby, FXList with (sunken) Frame
 
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 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.




All times are GMT. The time now is 11:21 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.