November 19th, 2010, 07:21 PM
What does this mean? I'm a beginner. Cheers ;)
My first post so go easy . I'm new to Ruby and I wanted a hand on something? Can you help me with these?
I'm going through a ruby book but I want to know what everything does in this code.
- Explain what the following code does. What class does the object that a refers to belong? How does the each method work?
a = [1,2,3,4,5,6,7]
like what does "|" mean before and after the "x"?
I know "puts" is like print line. And x.to_s is change x to string.
What is .each? And is a= [1,2...] declaring what "a" is?
November 22nd, 2010, 10:15 AM
assignment, Arrays, blocks
a is being assigned to an instance of the Array class created with the  notation.
each is an instance method of the Array class that accepts a block and passes each member of the array to the block.
|x| is just the notation used to name the argument within the scope of the block.