2 questions from a beginner

D

Diego Virasoro

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
 
J

Jan Svitok

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
 
D

Diego Virasoro

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
 

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

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,089
Members
47,687
Latest member
IngridXxj

Latest Threads

Top