(no subject)

Date: 2009-05-26 01:02 am (UTC)
tassosss: Shen Wei Zhao Yunlan Era (Default)
From: [personal profile] tassosss
Okay. I think I have this but I just want to clarify how the |variable| works.
The block is this (ps I love your examples!)

companions.each do |companion|
puts companion.upcase + '!'
end

What happens is that the .each takes the first name in the array and sends it to the block where the block says "you're my input and I'm going to now call you 'companion'." Then the block says "since you are a 'companion' I'm going to output you in all caps with an exclamation point." Now the block's job is done and the .each sends it the next item in the array.

Essentially the |companion| is only relevant for the block itself and once the array item leaves the block it's no longer associated with the 'companion' variable. Is that right?
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

July 2010

S M T W T F S
    123
4567 8910
11121314151617
18192021222324
25262728293031

Style Credit

Expand Cut Tags

No cut tags