[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

newby question determining name of an array at run-time

Alfonso

11/30/2006 11:48:00 PM

(Sorry for not finding a better title to my question. I'm not shure if
this has something to do with metaprogramming... I have hear about that,
but never had time to learn about it, so I don't know what is
metaprogramming exactly)

Is there a way to do something like this?

arr = [ "red", "green", "yellow" ]


# the following arrays should be incremented with the loop down
@red = []
@green = []
@yellow = []

#here the loop that should increment the arrays
20.times do
arr.each { |color|
rand(60)
unless @color.include?(aleat) #this doesn't work
@color.push(aleat) # this doesn't work...
end
}
end
...
...


Thanks in advance.


______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice...

12 Answers

Paul Lutus

12/1/2006 12:30:00 AM

0

Alfonso wrote:

> (Sorry for not finding a better title to my question. I'm not shure if
> this has something to do with metaprogramming... I have hear about that,
> but never had time to learn about it, so I don't know what is
> metaprogramming exactly)
>
> Is there a way to do something like this?
>
> arr = [ "red", "green", "yellow" ]
>
>
> # the following arrays should be incremented with the loop down
> @red = []
> @green = []
> @yellow = []

Are you after named arrays? Do it this way:

hash = {}

hash[:red] = []
hash[:green] = []
hash[:blue] = []


hash.keys.each do |color|
array = hash[color]
#do something here
end

But if you need to go through the colors in a particular order:

[ :red,:green,:blue ].each do |color|
# etc.

>
> #here the loop that should increment the arrays
> 20.times do
> arr.each { |color|
> rand(60)
> unless @color.include?(aleat) #this doesn't work
> @color.push(aleat) # this doesn't work...
> end
> }
> end

It always helps for you to say what you are trying to do, not just that it
didn't work.

--
Paul Lutus
http://www.ara...

Max Muermann

12/1/2006 2:56:00 AM

0

On 12/1/06, Alfonso <rubyeu@yahoo.es> wrote:
> (Sorry for not finding a better title to my question. I'm not shure if
> this has something to do with metaprogramming... I have hear about that,
> but never had time to learn about it, so I don't know what is
> metaprogramming exactly)
>
> Is there a way to do something like this?
>
> arr = [ "red", "green", "yellow" ]
>
>
> # the following arrays should be incremented with the loop down
> @red = []
> @green = []
> @yellow = []
>
> #here the loop that should increment the arrays
> 20.times do
> arr.each { |color|
> rand(60)
> unless @color.include?(aleat) #this doesn't work
> @color.push(aleat) # this doesn't work...
> end
> }
> end
> ...
> ...
>

Have a look at instance_variable_get in the RDocs - that'll do what you want.

Cheers,
Max

Alfonso

12/1/2006 12:06:00 PM

0

The method instance_variable_get was exactly what I needed.

Thank you very much for your answers




______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y móviles desde 1 céntimo por minuto.
http://es.voice...

Gray Guest

3/8/2013 11:50:00 PM

0

Jeff M <NoSpam@NoThanks.org> wrote in
news:9ZCdnXqENP8A3qfMnZ2dnUVZ_vGdnZ2d@giganews.com:

> On 3/3/2013 11:23 AM, Gray Guest wrote:
>> Jeff M <NoSpam@NoThanks.org> wrote in news:FtedncwWtoZxh6
>> _MnZ2dnUVZ_r2dnZ2d@giganews.com:
>>
>>> On 3/2/2013 11:02 AM, Oglethorpe wrote:
>>>> "Winston_Smith" <invalid@butterfly.net> wrote in message
>>>> news:3f12j8tj4r79vmc3n7nplp936p6htcat00@4ax.com...
>>>>> On Fri, 01 Mar 2013 12:59:04 -0500, Ed Huntress
>>>>> <huntres23@optonline.net> wrote:
>>>>>
>>>>>> But buy American! And don't worry about spending the kids' college
>>>>>> money. There won't be any college unless you have enough ammo.
>>>>>
>>>>> Do you seriously believe any significant fraction of the population
>>>>> can afford to save toward their kids' education?
>>>>
>>>>
>>>> Thank Democrats for that..
>>>
>>> Yeah, those Democrats are always opposing things like Pell Grants,
>>> tuition assistance for low-income families, tuition tax credits and
>>> low-interest student loans, ... oh, wait a minute ... oh, wait, those
>>> are things Democrats did that Republicans opposed, so, um, nevermind.
>>>
>> Funny, they never seem to want to control costs on campus though. The
>> lickspittle profs clean up and the graduates are indebted for life and
on
>> foold stamps.
>>
>> What a great plan.
>
> The academics don't have much day to day control over the financial
> administration of most universities, but, from a financial perspective,
> colleges are run like a racket.
>
>
>

We agree on something again.

Frankly I think the whole universtiy system has become a big con.

A lot of people would be much better off getting blue collar skills and
going to work. I work in tech but I could never sit still in a classroom. I
learn differently and frankly I beleive myself to be better equipped for my
business than many folks with a BS in CS and $100,000 or more in debt to
start their professional careers.

--
Refusenik #1

Libs suffer from Eleutherophobia. And there is no cure.

Obama called the SEALs and THEY got bin Laden. When the SEALs called Obama,
THEY GOT DENIED. Fuck Obama

Jeff M

3/9/2013 11:21:00 AM

0

On 3/8/2013 5:50 PM, Gray Guest wrote:
> Jeff M <NoSpam@NoThanks.org> wrote in
> news:9ZCdnXqENP8A3qfMnZ2dnUVZ_vGdnZ2d@giganews.com:
>
>> On 3/3/2013 11:23 AM, Gray Guest wrote:
>>> Jeff M <NoSpam@NoThanks.org> wrote in news:FtedncwWtoZxh6
>>> _MnZ2dnUVZ_r2dnZ2d@giganews.com:
>>>
>>>> On 3/2/2013 11:02 AM, Oglethorpe wrote:
>>>>> "Winston_Smith" <invalid@butterfly.net> wrote in message
>>>>> news:3f12j8tj4r79vmc3n7nplp936p6htcat00@4ax.com...
>>>>>> On Fri, 01 Mar 2013 12:59:04 -0500, Ed Huntress
>>>>>> <huntres23@optonline.net> wrote:
>>>>>>
>>>>>>> But buy American! And don't worry about spending the kids' college
>>>>>>> money. There won't be any college unless you have enough ammo.
>>>>>>
>>>>>> Do you seriously believe any significant fraction of the population
>>>>>> can afford to save toward their kids' education?
>>>>>
>>>>>
>>>>> Thank Democrats for that..
>>>>
>>>> Yeah, those Democrats are always opposing things like Pell Grants,
>>>> tuition assistance for low-income families, tuition tax credits and
>>>> low-interest student loans, ... oh, wait a minute ... oh, wait, those
>>>> are things Democrats did that Republicans opposed, so, um, nevermind.
>>>>
>>> Funny, they never seem to want to control costs on campus though. The
>>> lickspittle profs clean up and the graduates are indebted for life and
> on
>>> foold stamps.
>>>
>>> What a great plan.
>>
>> The academics don't have much day to day control over the financial
>> administration of most universities, but, from a financial perspective,
>> colleges are run like a racket.
>>
> We agree on something again.
>
> Frankly I think the whole universtiy system has become a big con.
>
> A lot of people would be much better off getting blue collar skills and
> going to work.

College ain't for everybody. But on the other hand, very few people
have actually been harmed by having a college education either.

Personally, I think it's useful to have both types. For one thing, my
blue collar skills paid my and my wife's way through college and grad
school.

> I work in tech but I could never sit still in a classroom. I
> learn differently and frankly I beleive myself to be better equipped for my
> business than many folks with a BS in CS and $100,000 or more in debt to
> start their professional careers.

No doubt. College debt kills opportunity, flexibility,
entrepreneurship, risk-taking and public service.


pyotr filipivich

3/18/2013 5:15:00 PM

0

Gray Guest <No_email_for_you@wahoo.com> on Sun, 3 Mar 2013 17:23:40
+0000 (UTC) typed in misc.survivalism the following:
>Jeff M <NoSpam@NoThanks.org> wrote:
>> On 3/2/2013 11:02 AM, Oglethorpe wrote:
>>> "Winston_Smith" <invalid@butterfly.net> wrote:
>>>> On Fri, 01 Mar 2013 12:59:04 -0500, Ed Huntress wrote:
>>>>
>>>>> But buy American! And don't worry about spending the kids' college
>>>>> money. There won't be any college unless you have enough ammo.
>>>>
>>>> Do you seriously believe any significant fraction of the population
>>>> can afford to save toward their kids' education?
>>>
>>> Thank Democrats for that..
>>
>> Yeah, those Democrats are always opposing things like Pell Grants,
>> tuition assistance for low-income families, tuition tax credits and
>> low-interest student loans, ... oh, wait a minute ... oh, wait, those
>> are things Democrats did that Republicans opposed, so, um, nevermind.
>>
>Funny, they never seem to want to control costs on campus though. The
>lickspittle profs clean up

Tain't so much the professors, as it is the Administrators.
Million dollar president salaries, salaries for the staff for the
Office of Diversity, the Human Right's Council, the GLBTASW&S council,
The Mecha/LaRaza Anti Racism Alliance. Not to mention the facilitators
at the Student Fitness Center, the Wymins Helth Center, the
alternative non-traditionally religious outreach.

> and the graduates are indebted for life and on foold stamps.
>
>What a great plan.

Works for them, why should they care?

What the progressive seem to have forgotten is, that it is within
living memory of a time when you could work your way through college.
Part time work even. (Dad was a soda jerk for a while, Petros rebuilt
and sold cars.)
--
pyotr filipivich.
Just about the time you finally see light at the end of the tunnel,
you find out it's a Government Project to build more tunnel.

Jeff M

3/18/2013 6:33:00 PM

0

On 3/18/2013 12:14 PM, pyotr filipivich wrote:
> Gray Guest <No_email_for_you@wahoo.com> on Sun, 3 Mar 2013 17:23:40
> +0000 (UTC) typed in misc.survivalism the following:
>> Jeff M <NoSpam@NoThanks.org> wrote:
>>> On 3/2/2013 11:02 AM, Oglethorpe wrote:
>>>> "Winston_Smith" <invalid@butterfly.net> wrote:
>>>>> On Fri, 01 Mar 2013 12:59:04 -0500, Ed Huntress wrote:
>>>>>
>>>>>> But buy American! And don't worry about spending the kids' college
>>>>>> money. There won't be any college unless you have enough ammo.
>>>>>
>>>>> Do you seriously believe any significant fraction of the population
>>>>> can afford to save toward their kids' education?
>>>>
>>>> Thank Democrats for that..
>>>
>>> Yeah, those Democrats are always opposing things like Pell Grants,
>>> tuition assistance for low-income families, tuition tax credits and
>>> low-interest student loans, ... oh, wait a minute ... oh, wait, those
>>> are things Democrats did that Republicans opposed, so, um, nevermind.
>>>
>> Funny, they never seem to want to control costs on campus though. The
>> lickspittle profs clean up
>
> Tain't so much the professors, as it is the Administrators.
> Million dollar president salaries, salaries for the staff for the
> Office of Diversity, the Human Right's Council, the GLBTASW&S council,
> The Mecha/LaRaza Anti Racism Alliance. Not to mention the facilitators
> at the Student Fitness Center, the Wymins Helth Center, the
> alternative non-traditionally religious outreach.
>
>> and the graduates are indebted for life and on foold stamps.
>>
>> What a great plan.
>
> Works for them, why should they care?
>
> What the progressive seem to have forgotten is, that it is within
> living memory of a time when you could work your way through college.
> Part time work even. (Dad was a soda jerk for a while, Petros rebuilt
> and sold cars.)

But you couldn't manage to do what your dad was able to do? Obviously,
from your laughable assertions about colleges, it would appear you've
never spent much, if any, time actually studying at one.

Jeff M

3/18/2013 7:12:00 PM

0

On 3/18/2013 1:54 PM, benj wrote:
> On Mon, 18 Mar 2013 13:32:41 -0500, Jeff M wrote:
>
>>> What the progressive seem to have forgotten is, that it is within
>>> living memory of a time when you could work your way through college.
>>> Part time work even. (Dad was a soda jerk for a while, Petros rebuilt
>>> and sold cars.)
>>
>> But you couldn't manage to do what your dad was able to do? Obviously,
>> from your laughable assertions about colleges, it would appear you've
>> never spent much, if any, time actually studying at one.
>
> Obviously you were born yesterday and hence can't remember when tuition
> for residents at State Universities was like $35! Now tell me that the
> increase is all due to "inflation"!

I'm old enough to remember my sister paying $50 per semester to study
mathematics at Berkeley.

College tuition rate increases have outstripped inflation for many
years, due to a variety of factors, some not very sensible. Nonetheless,
some colleges have endowments so enormous that they have no real
justification to charge anybody tuition, ever again. Even at state
colleges, if I understand correctly, the taxpayers are paying about 3/4
of the actual costs, with tuition covering the rest. The net effect of
this is that "Joe and Jill Lunchbucket," average middle class folks,
have effectively paid most of the college costs for their kids already.
The remaining tuition therefore serves mainly as a bar or impediment
to prevent their kids from obtaining the boon of the college education
that they are already paying most of the costs for. It is in the
economic interest of the nation to make higher education as widely and
affordably available as possible for meritorious students. Doing
otherwise is the equivalent of a farmer eating his seed corn.

I worked full time while attending college full time and paying both my
and my wife's tuition through college and also through grad school,
where tuition was double the undergraduate rate. It was the financial
equivalent of putting four kids through college at the same time. It
wasn't easy, but it is doable if you are motivated and willing to work hard.


Gray Guest

3/18/2013 11:54:00 PM

0

Jeff M <NoSpam@NoThanks.org> wrote in news:1YmdnRLCp-
FWwNrMnZ2dnUVZ_r6dnZ2d@giganews.com:

> On 3/18/2013 12:14 PM, pyotr filipivich wrote:
>> Gray Guest <No_email_for_you@wahoo.com> on Sun, 3 Mar 2013 17:23:40
>> +0000 (UTC) typed in misc.survivalism the following:
>>> Jeff M <NoSpam@NoThanks.org> wrote:
>>>> On 3/2/2013 11:02 AM, Oglethorpe wrote:
>>>>> "Winston_Smith" <invalid@butterfly.net> wrote:
>>>>>> On Fri, 01 Mar 2013 12:59:04 -0500, Ed Huntress wrote:
>>>>>>
>>>>>>> But buy American! And don't worry about spending the kids' college
>>>>>>> money. There won't be any college unless you have enough ammo.
>>>>>>
>>>>>> Do you seriously believe any significant fraction of the population
>>>>>> can afford to save toward their kids' education?
>>>>>
>>>>> Thank Democrats for that..
>>>>
>>>> Yeah, those Democrats are always opposing things like Pell Grants,
>>>> tuition assistance for low-income families, tuition tax credits and
>>>> low-interest student loans, ... oh, wait a minute ... oh, wait, those
>>>> are things Democrats did that Republicans opposed, so, um, nevermind.
>>>>
>>> Funny, they never seem to want to control costs on campus though. The
>>> lickspittle profs clean up
>>
>> Tain't so much the professors, as it is the Administrators.
>> Million dollar president salaries, salaries for the staff for the
>> Office of Diversity, the Human Right's Council, the GLBTASW&S council,
>> The Mecha/LaRaza Anti Racism Alliance. Not to mention the facilitators
>> at the Student Fitness Center, the Wymins Helth Center, the
>> alternative non-traditionally religious outreach.
>>
>>> and the graduates are indebted for life and on foold stamps.
>>>
>>> What a great plan.
>>
>> Works for them, why should they care?
>>
>> What the progressive seem to have forgotten is, that it is within
>> living memory of a time when you could work your way through college.
>> Part time work even. (Dad was a soda jerk for a while, Petros rebuilt
>> and sold cars.)
>
> But you couldn't manage to do what your dad was able to do? Obviously,
> from your laughable assertions about colleges, it would appear you've
> never spent much, if any, time actually studying at one.
>
>

You really are an arrogant, smug prig.

--
Refusenik #1

Libs suffer from Eleutherophobia. And there is no cure.

Obama called the SEALs and THEY got bin Laden. When the SEALs called Obama,
THEY GOT DENIED. Fuck Obama

Jeff M

3/19/2013 12:24:00 AM

0

On 3/18/2013 6:53 PM, Gray Guest wrote:
> Jeff M <NoSpam@NoThanks.org> wrote in news:1YmdnRLCp-
> FWwNrMnZ2dnUVZ_r6dnZ2d@giganews.com:
>
>> On 3/18/2013 12:14 PM, pyotr filipivich wrote:
>>> Gray Guest <No_email_for_you@wahoo.com> on Sun, 3 Mar 2013 17:23:40
>>> +0000 (UTC) typed in misc.survivalism the following:
>>>> Jeff M <NoSpam@NoThanks.org> wrote:
>>>>> On 3/2/2013 11:02 AM, Oglethorpe wrote:
>>>>>> "Winston_Smith" <invalid@butterfly.net> wrote:
>>>>>>> On Fri, 01 Mar 2013 12:59:04 -0500, Ed Huntress wrote:
>>>>>>>
>>>>>>>> But buy American! And don't worry about spending the kids' college
>>>>>>>> money. There won't be any college unless you have enough ammo.
>>>>>>>
>>>>>>> Do you seriously believe any significant fraction of the population
>>>>>>> can afford to save toward their kids' education?
>>>>>>
>>>>>> Thank Democrats for that..
>>>>>
>>>>> Yeah, those Democrats are always opposing things like Pell Grants,
>>>>> tuition assistance for low-income families, tuition tax credits and
>>>>> low-interest student loans, ... oh, wait a minute ... oh, wait, those
>>>>> are things Democrats did that Republicans opposed, so, um, nevermind.
>>>>>
>>>> Funny, they never seem to want to control costs on campus though. The
>>>> lickspittle profs clean up
>>>
>>> Tain't so much the professors, as it is the Administrators.
>>> Million dollar president salaries, salaries for the staff for the
>>> Office of Diversity, the Human Right's Council, the GLBTASW&S council,
>>> The Mecha/LaRaza Anti Racism Alliance. Not to mention the facilitators
>>> at the Student Fitness Center, the Wymins Helth Center, the
>>> alternative non-traditionally religious outreach.
>>>
>>>> and the graduates are indebted for life and on foold stamps.
>>>>
>>>> What a great plan.
>>>
>>> Works for them, why should they care?
>>>
>>> What the progressive seem to have forgotten is, that it is within
>>> living memory of a time when you could work your way through college.
>>> Part time work even. (Dad was a soda jerk for a while, Petros rebuilt
>>> and sold cars.)
>>
>> But you couldn't manage to do what your dad was able to do? Obviously,
>> from your laughable assertions about colleges, it would appear you've
>> never spent much, if any, time actually studying at one.
>>
> You really are an arrogant, smug prig.

Says one of the leading ridiculous blowhards of the infobahn.

Although you have considerable expertise in arrogant smugness yourself,
by dent of long practice, you are wrong, as usual, as was the OP about
why college costs are so high. Instead, the OP just regurgitated the
same old standard regressive anti-academic nonsense.

Moreover, regressives have an anti-academic agenda, and have admitted
that it is because higher education undermines blind, unquestioning
acceptance of their political dogma. So they bear considerable
responsibility for making higher education less affordable and less
available to the children of ordinary working class families. They
actually count this as one of their successes. Of course, even you know
I'm right, which explains why you chose a silly, meaningless personal
attack instead of trying to refute what I said.