[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How does array.each element work?

Neela megha shyam Chivukula

5/22/2009 10:50:00 AM

Hi All,

Here is my code snippet:-
my_array = [1,2,3]
puts my_array.each {}

or

my_array = [1,2,3]
my_array.each {|x| puts x}

O/p:-
1
2
3

I want to know how the array.each works. How the compiler interprets and
prints.

Thanks and regards,
Neela.
--
Posted via http://www.ruby-....

4 Answers

Lamont Cranston

6/16/2008 6:28:00 PM

0

David Moffitt wrote:
> "Lamont Cranston" <Lamont.Cranston@penumbra.com> wrote in message
> news:g363k0$sqp$1@news.datemas.de...
> | ObamaWillDestroyUSA wrote:
> | > Not one black has contributed to the 10's of thousand white
> | > people in the midwest who have been flooded out of their homes.
> |
> | Thanks for pointing out the income disparities that still exist in
> | this country.
>
> %%%% Why does it exist?

Because of people like you.

> Do you think an 8th grade dropout (keeping it
> real!) should makes as much money as someone who finished highschool
> or went to college? Everyone has an equal opportunity to succeed
> there is no guarentee of equal outcome. Everyone cannot be Bill Gates.

No, everyone does not have an equal opportunity to succeed. That is what
you wingnuts would like us to believe while simultaneously discriminating
against anybody with dark skin. You GOP cocksuckers are despicable.

David Moffitt

6/16/2008 11:30:00 PM

0


"Lamont Cranston" <Lamont.Cranston@penumbra.com> wrote in message
news:g36b9f$c2j$1@news.datemas.de...
| David Moffitt wrote:
| > "Lamont Cranston" <Lamont.Cranston@penumbra.com> wrote in message
| > news:g363k0$sqp$1@news.datemas.de...
| > | ObamaWillDestroyUSA wrote:
| > | > Not one black has contributed to the 10's of thousand white
| > | > people in the midwest who have been flooded out of their homes.
| > |
| > | Thanks for pointing out the income disparities that still exist in
| > | this country.
| >
| > %%%% Why does it exist?
|
| Because of people like you.
|
| > Do you think an 8th grade dropout (keeping it
| > real!) should makes as much money as someone who finished highschool
| > or went to college? Everyone has an equal opportunity to succeed
| > there is no guarentee of equal outcome. Everyone cannot be Bill Gates.
|
| No, everyone does not have an equal opportunity to succeed. That is what
| you wingnuts would like us to believe while simultaneously discriminating
| against anybody with dark skin. You GOP cocksuckers are despicable.


%%%% Highschool is free and if you apply yourself so is college in my state.
What do you mean by discrimination white boy?

"My sense of purpose is gone! I have no idea who I AM!"
"Oh, my God... You've.. You've turned him into a DEMOCRAT!" -- Doonesbury



Andrew Timberlake

5/22/2009 11:13:00 AM

0

On Fri, May 22, 2009 at 12:49 PM, Neela megha shyam Chivukula
<indrashyam@gmail.com> wrote:
> Hi All,
>
> Here is my code snippet:-
> my_array = [1,2,3]
> puts my_array.each {}
>
> or
>
> my_array = [1,2,3]
> my_array.each {|x| puts x}
>
> O/p:-
> 1
> 2
> 3
>
> I want to know how the array.each works. How the compiler interprets and
> prints.
>
> Thanks and regards,
> Neela.


http://www.ruby-doc.org/core/classes/SOAP/RPC/SOAPMethodResponse.ht...
each will iterate over each element in the array and then yield to a
supplied block with a single variable, the item in the array.
If you have a look at the C code, you'll see a familiar looking for
loop with calls to yield.

For a better understanding, you need to do some further reading on
blocks in ruby.

Start with http://www.rubycentral.com/book/tut_conta...

Andrew Timberlake
http://ramblingso...

http://MyM... - The SIMPLE way to manage your savings

Neela megha shyam Chivukula

5/23/2009 8:09:00 AM

0

Andrew Timberlake wrote:
> On Fri, May 22, 2009 at 12:49 PM, Neela megha shyam Chivukula
> <indrashyam@gmail.com> wrote:
>>
>> O/p:-
>> 1
>> 2
>> 3
>>
>> I want to know how the array.each works. How the compiler interprets and
>> prints.
>>
>> Thanks and regards,
>> Neela.
>
>
> http://www.ruby-doc.org/core/classes/SOAP/RPC/SOAPMethodResponse.ht...
> each will iterate over each element in the array and then yield to a
> supplied block with a single variable, the item in the array.
> If you have a look at the C code, you'll see a familiar looking for
> loop with calls to yield.
>
> For a better understanding, you need to do some further reading on
> blocks in ruby.
>
> Start with http://www.rubycentral.com/book/tut_conta...
>
> Andrew Timberlake
> http://ramblingso...
>
> http://MyM... - The SIMPLE way to manage your savings

Hi Andrew,

I will go through the link. Thank you.

Thanks and regards,
Neela.
--
Posted via http://www.ruby-....