[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

2 questions from a beginner

Diego Virasoro

8/16/2006 4:47:00 PM

Hi,
I am currently trying to find the solution to these two problems, but
my first look at the documentation didn't give any good answer, so here
I go... :)

1-I would like my ruby program to call shell command "ps". So far I've
found I can use Kernel#system and Kernel#exec but I need to save the
result into a variable so that I can then manipulate it and neither of
these seem to help there. How could I do this?

2-In creating a simple Tk interface I need to have 3 labels and 3 text
entries connected with 3 variables. So for example I would have:
1-labels: hoursLabel, minsLabel, secsLabel
2-entries: hoursEntry, minsEntry, secsEntry
3-variables: hoursVariable, minsVariable, secsVariable

As you can imagine there is a lot of repetition in the code, so I was
wondering if there is any way to create a variable called, say, xEntry
where x is itself a string stored in another variable. In this way I
could have three string variables "hours", "mins", "secs", and the
computer would create the 9 variables listed above and initialize them
(since the initialization code is almost identical)

Mmm... I hope I was clear.

Thanks in advance

Diego Virasoro

7 Answers

Jano Svitok

8/16/2006 5:01:00 PM

0

On 8/16/06, Diego Virasoro <Diego.Virasoro@gmail.com> wrote:
> Hi,
> I am currently trying to find the solution to these two problems, but
> my first look at the documentation didn't give any good answer, so here
> I go... :)
>
> 1-I would like my ruby program to call shell command "ps". So far I've
> found I can use Kernel#system and Kernel#exec but I need to save the
> result into a variable so that I can then manipulate it and neither of
> these seem to help there. How could I do this?
>
> 2-In creating a simple Tk interface I need to have 3 labels and 3 text
> entries connected with 3 variables. So for example I would have:
> 1-labels: hoursLabel, minsLabel, secsLabel
> 2-entries: hoursEntry, minsEntry, secsEntry
> 3-variables: hoursVariable, minsVariable, secsVariable
>
> As you can imagine there is a lot of repetition in the code, so I was
> wondering if there is any way to create a variable called, say, xEntry
> where x is itself a string stored in another variable. In this way I
> could have three string variables "hours", "mins", "secs", and the
> computer would create the 9 variables listed above and initialize them
> (since the initialization code is almost identical)
>
> Mmm... I hope I was clear.
>
> Thanks in advance
>
> Diego Virasoro

Hi,

try:
1. out = `ps` (Kernel#backtick)
2. Object#instance_variable_set( "@#{x}Entry") if it is an instance variable
eval "#{x}Entry = whatever you need" otherwise

Diego Virasoro

8/17/2006 1:22:00 AM

0

> 1. out = `ps` (Kernel#backtick)
> 2. Object#instance_variable_set( "@#{x}Entry") if it is an instance variable
> eval "#{x}Entry = whatever you need" otherwise

Thanks a lot. Both worked just as I needed them. :)

Diego

Kay Shapero

5/12/2009 6:11:00 AM

0

In article <gu7kss$2of$2@news.motzarella.org>,
seawasp@sgeinc.invalid.com says...
> Tina Hall wrote:
> > Sea Wasp (Ryk E. Spoor) <seawasp@sgeinc.invalid.com> wrote:
> >> Tina Hall wrote:
> >
> >>> I see I could get:
> >>>
> >>> rec.games.frp.*
> >
> >> I don't think ANY of those have Intense Traffic.
> >
> > Are you sure any of them have any traffic? (So far nothing has
> > arrived here.)
> >
> > If you say there's something going on in any of them (please name
> > them if that's not too much of a bother), I'll bother my node again.
>
> Well, there's certainly been SOME things in rec.games.frp.dnd, as I
> have made at least three or four posts there in the last few days, to
> which some people have responded.
>
FWIW I picked up rec.games.frp and made an "anybody home" post. Alas,
it seems to be the only post in there, today. You folks find anything
active and I'll come join in myself.

--
Kay Shapero
address munged, email kay at following domain
http://www.kays...

goldfarb

5/12/2009 8:36:00 AM

0

In article <MPG.2472b2b0a0de0831989836@news.west.earthlink.net>,
Kay Shapero <kay@invalid.net> wrote:
>FWIW I picked up rec.games.frp and made an "anybody home" post. Alas,
>it seems to be the only post in there, today. You folks find anything
>active and I'll come join in myself.

rec.games.frp got split up ages and ages ago. In such cases, use
of the root group is deprecated -- so for instance if you were to
try to post to rec.arts.comics, there'd be nothing there either.
Try rec.games.frp.misc.

--
David Goldfarb |"Oh, no! They've all become giant Swiss
goldfarb@ocf.berkeley.edu | lederhosen-clad dancing yodelers!"
goldfarb@csua.berkeley.edu | -- Animaniacs

Sea Wasp (Ryk E. Spoor)

5/12/2009 11:39:00 AM

0

Kay Shapero wrote:
> In article <gu7kss$2of$2@news.motzarella.org>,
> seawasp@sgeinc.invalid.com says...
>> Tina Hall wrote:
>>> Sea Wasp (Ryk E. Spoor) <seawasp@sgeinc.invalid.com> wrote:
>>>> Tina Hall wrote:
>>>>> I see I could get:
>>>>>
>>>>> rec.games.frp.*
>>>> I don't think ANY of those have Intense Traffic.
>>> Are you sure any of them have any traffic? (So far nothing has
>>> arrived here.)
>>>
>>> If you say there's something going on in any of them (please name
>>> them if that's not too much of a bother), I'll bother my node again.
>> Well, there's certainly been SOME things in rec.games.frp.dnd, as I
>> have made at least three or four posts there in the last few days, to
>> which some people have responded.
>>
> FWIW I picked up rec.games.frp and made an "anybody home" post.

Rec.games.frp is a root group that hasn't existed for, I dunno, fifteen
years? Might as well post to rec.arts.sf .

rec.games.frp.dnd, rec.games.frp.misc, etc., exist, but not rec.games.frp.

--
Sea Wasp
/^ ;;;
Live Journal: http://seawasp.livej...

Sea Wasp (Ryk E. Spoor)

5/12/2009 10:58:00 PM

0

David Goldfarb wrote:
> In article <gubn4j$ae4$2@news.motzarella.org>,
> Sea Wasp (Ryk E. Spoor) <seawasp@sgeinc.invalid.com> wrote:
>> Rec.games.frp is a root group that hasn't existed for, I dunno, fifteen
>> years? Might as well post to rec.arts.sf .
>
> A nitpick: that's not the best possible example, because there
> never was a rec.arts.sf, while there did used to be a rec.games.frp.
> (Wasp knows this, but others might not: It used to be
> rec.arts.sf-lovers, because the USENET group was derived from a
> mailing list called "SF-LOVERS".)
>


Nyaah, nyaah nitpicker. Fine. Might as well post to rec.arts.anime .

--
Sea Wasp
/^ ;;;
Live Journal: http://seawasp.livej...

Kay Shapero

5/13/2009 1:38:00 AM

0

Ok, I've moved to rec.games.frp.dnd

--
Kay Shapero
address munged, email kay at following domain
http://www.kays...