2 questions from a beginner

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… :slight_smile:

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

On 8/16/06, Diego V. [email protected] wrote:

2-In creating a simple Tk interface I need to have 3 labels and 3 text
(since the initialization code is almost identical)

Mmm… I hope I was clear.

Thanks in advance

Diego V.

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
  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. :slight_smile:

Diego

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs