[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

|song| Not documented in Pickaxe Book

Sam'l B

12/22/2006 1:45:00 AM

Pickaxe Book (2nd Ed.), P. 49, 2nd example, line 3:

@songs.find {|song| title == song.name }

I can't find a definition of the "|song|" construction in the book.
It is intuitively obvious that it is a variable, and a sort of
"catcher's mitt" for the output of the method "@songs.find" -- and acts
that way for all other example in the book that I can find.

What I _can't_ find, though, is a discussion of the construction -- or
did I miss it somewhere?

Sam Bassett

10 Answers

Tim Hunter

12/22/2006 2:15:00 AM

0

Sam'l B wrote:
> Pickaxe Book (2nd Ed.), P. 49, 2nd example, line 3:
>
> @songs.find {|song| title == song.name }
>
> I can't find a definition of the "|song|" construction in the
> book. It is intuitively obvious that it is a variable, and a sort of
> "catcher's mitt" for the output of the method "@songs.find" -- and
> acts that way for all other example in the book that I can find.
>
> What I _can't_ find, though, is a discussion of the construction
> -- or did I miss it somewhere?
>
> Sam Bassett
>
In the Pickaxe 2nd Ed., look at the top of page 76.




Sam'l B

12/22/2006 2:26:00 AM

0

Nope -- P. 76 has a discussion of gsub, in the context of "Backslash
Sequences in the Substitution"

Timothy Hunter wrote:
> Sam'l B wrote:
>> Pickaxe Book (2nd Ed.), P. 49, 2nd example, line 3:
>>
>> @songs.find {|song| title == song.name }
>>
>> I can't find a definition of the "|song|" construction in the
>> book. It is intuitively obvious that it is a variable, and a sort of
>> "catcher's mitt" for the output of the method "@songs.find" -- and
>> acts that way for all other example in the book that I can find.
>>
>> What I _can't_ find, though, is a discussion of the construction
>> -- or did I miss it somewhere?
>>
>> Sam Bassett
>>
> In the Pickaxe 2nd Ed., look at the top of page 76.
>

dblack

12/22/2006 2:37:00 AM

0

Jeremy McAnally

12/22/2006 2:38:00 AM

0

That is a parameter passed to a block. It allows the method that
yielded to the block to pass information into the block, which in this
case is a song title (I'm guessing?).

Think of it (sort of) as the method yielding to the block feeding it a
parameter like you would a method call: a value is passed in from the
caller and stored in a local instance to be used in the block.

--Jeremy

On 12/21/06, Sam'l B <samlb@samlb.ws> wrote:
> Nope -- P. 76 has a discussion of gsub, in the context of "Backslash
> Sequences in the Substitution"
>
> Timothy Hunter wrote:
> > Sam'l B wrote:
> >> Pickaxe Book (2nd Ed.), P. 49, 2nd example, line 3:
> >>
> >> @songs.find {|song| title == song.name }
> >>
> >> I can't find a definition of the "|song|" construction in the
> >> book. It is intuitively obvious that it is a variable, and a sort of
> >> "catcher's mitt" for the output of the method "@songs.find" -- and
> >> acts that way for all other example in the book that I can find.
> >>
> >> What I _can't_ find, though, is a discussion of the construction
> >> -- or did I miss it somewhere?
> >>
> >> Sam Bassett
> >>
> > In the Pickaxe 2nd Ed., look at the top of page 76.
> >
>
>

Giles Bowkett

12/22/2006 3:03:00 AM

0

The online version of the first edition of Pickaxe has it here:

http://www.rubycentral.com/book/...

Scroll down to "Blocks and Iterators." It's about 2/3rds down the page.

--
Giles Bowkett
http://www.gilesg...
http://gilesbowkett.bl...
http://gilesgoatboy.bl...

Devin Mullins

12/22/2006 3:42:00 AM

0

Giles Bowkett wrote:
> The online version of the first edition of Pickaxe has it here:
>
> http://www.rubycentral.com/book/...
>
> Scroll down to "Blocks and Iterators." It's about 2/3rds down the page.

Here's an URL with an anchor link, for the especially lazy:
http://phrogz.net/ProgrammingRuby/language.html#blocksclosuresandp...

Note the mention of the rules of parallel assignment, and click the
link. You'll get more info than you ever wanted to know.

Or, at least, *should* have wanted to know. With irb and Test::Unit, who
needs to remember these details?

Devin

Sam'l B

12/22/2006 6:34:00 AM

0

dblack@wobblini.net wrote:
> Hi --
>
> On Fri, 22 Dec 2006, Sam'l B wrote:
>
>> Nope -- P. 76 has a discussion of gsub, in the context of
>> "Backslash Sequences in the Substitution"
>
> Look in the middle of page 22.
>
>
> David
>
Got it! Thanks!


Sam'l B

12/22/2006 6:35:00 AM

0

Jeremy McAnally wrote:
> That is a parameter passed to a block. It allows the method that
> yielded to the block to pass information into the block, which in this
> case is a song title (I'm guessing?).
>
> Think of it (sort of) as the method yielding to the block feeding it a
> parameter like you would a method call: a value is passed in from the
> caller and stored in a local instance to be used in the block.

That's what I had figured out intuitively -- it catches whatever the
method on the left spits out.

Sam'l

>
> --Jeremy
>
> On 12/21/06, Sam'l B <samlb@samlb.ws> wrote:
>> Nope -- P. 76 has a discussion of gsub, in the context of
>> "Backslash
>> Sequences in the Substitution"
>>
>> Timothy Hunter wrote:
>> > Sam'l B wrote:
>> >> Pickaxe Book (2nd Ed.), P. 49, 2nd example, line 3:
>> >>
>> >> @songs.find {|song| title == song.name }
>> >>
>> >> I can't find a definition of the "|song|" construction in the
>> >> book. It is intuitively obvious that it is a variable, and a sort of
>> >> "catcher's mitt" for the output of the method "@songs.find" -- and
>> >> acts that way for all other example in the book that I can find.
>> >>
>> >> What I _can't_ find, though, is a discussion of the construction
>> >> -- or did I miss it somewhere?
>> >>
>> >> Sam Bassett
>> >>
>> > In the Pickaxe 2nd Ed., look at the top of page 76.
>> >
>>
>>
>
>
>


Sam'l B

12/22/2006 6:41:00 AM

0

Devin Mullins wrote:
> Giles Bowkett wrote:
>> The online version of the first edition of Pickaxe has it here:
>>
>> http://www.rubycentral.com/book/...
>>
>> Scroll down to "Blocks and Iterators." It's about 2/3rds down the page.
>
> Here's an URL with an anchor link, for the especially lazy:
> http://phrogz.net/ProgrammingRuby/language.html#blocksclosuresandp...
>
>
> Note the mention of the rules of parallel assignment, and click the
> link. You'll get more info than you ever wanted to know.
>
> Or, at least, *should* have wanted to know. With irb and Test::Unit, who
> needs to remember these details?

Documentation Nazis and other excessively literal folk,

Sam'l B.

rwtnorton

12/22/2006 7:52:00 AM

0


> Pickaxe Book (2nd Ed.), P. 49, 2nd example, line 3:
>
> @songs.find {|song| title == song.name }
>
> I can't find a definition of the "|song|" construction in the book.
> It is intuitively obvious that it is a variable, and a sort of
> "catcher's mitt" for the output of the method "@songs.find" -- and
> acts that way for all other example in the book that I can find.
>
> What I _can't_ find, though, is a discussion of the construction --
> or did I miss it somewhere?
>
> Sam Bassett
>
>


Why, it's a chute, of course:
http://poignantguide.net/ruby/chap... (Section: Block
Arguments)

;-)

(Definitely, my all-time favorite intro-to-a-programming-language text.)

Richard W. Norton