From: Brian Ross Date: 2008-08-29T04:27:00+09:00 Subject: Re: Writing a method to handle a code block? ------=_Part_9141_7046097.1219951903797 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Thu, Aug 28, 2008 at 1:36 PM, Adam Shelly wrote: > > code_block.call(vowel) is calling the method stored in the code_block > variable, and > passing it the argument called vowel. When you call each_vowel like this: > > each_vowel {|vowel| puts vowel} > > The block with 'puts' is stored as code_block, and run 5 times, once > for each letter in the array: > %w{a e i o u}.each { |vowel| code_block.call(vowel) } > > So the end result is that each vowel is printed out. > Intuitively I'd think that: each_vowel {|vowel| puts vowel} would lead to something that looked like: %w{a e i o u}.each { |vowel| |vowel| puts vowel.call(vowel) } which is incomprehensible to me. I guess I am trying to really figure out how it's working so that I can construct my own and really understand it. To sound like an idiot: I still don't really understand how it's working. Brian ------=_Part_9141_7046097.1219951903797--