#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    What does this mean? I'm a beginner. Cheers ;)


    Hi peeps,

    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]
    a.each{|x|puts x.to_s}

    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?

    Thank you,

    Zukky
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    7
    Rep Power
    0

    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.

IMN logo majestic logo threadwatch logo seochat tools logo