# 2 questions from a beginner

**URL:** <https://www.ruby-forum.com/t/2-questions-from-a-beginner/65189>\
**Category:** Ruby\
**Created:** [August 16, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/2-questions-from-a-beginner/65189 "2006-08-16T18:51:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![diego\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@diego\_v](https://www.ruby-forum.com/u/diego_v)\
**Post date:** [August 16, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/2-questions-from-a-beginner/65189/1 "2006-08-16T18:51:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![diego\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@diego\_v](https://www.ruby-forum.com/u/diego_v)\
**Post date:** [August 16, 2006, 7:03pm UTC](https://www.ruby-forum.com/t/2-questions-from-a-beginner/65189/2 "2006-08-16T19:03:33Z")

</div>

On 8/16/06, Diego V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![diego\_v](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eb8c5e/32.png) [@diego\_v](https://www.ruby-forum.com/u/diego_v)\
**Post date:** [August 17, 2006, 3:25am UTC](https://www.ruby-forum.com/t/2-questions-from-a-beginner/65189/3 "2006-08-17T03:25:24Z")

</div>

> 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
