Forum: Ruby |song| Not documented in Pickaxe Book

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bfab87df9f06c2a4ac1782e1fa794108?d=identicon&s=25 Sam'l B (Guest)
on 2006-12-22 02:46
(Received via mailing list)
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
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Timothy Hunter (Guest)
on 2006-12-22 03:16
(Received via mailing list)
Sam'l B wrote:
> -- or did I miss it somewhere?
>
> Sam Bassett
>
In the Pickaxe 2nd Ed., look at the top of page 76.
Bfab87df9f06c2a4ac1782e1fa794108?d=identicon&s=25 Sam'l B (Guest)
on 2006-12-22 03:28
(Received via mailing list)
Nope -- P. 76 has a discussion of gsub, in the context of "Backslash
Sequences in the Substitution"
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-12-22 03:38
(Received via mailing list)
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
6d3c187a8b3ef53b08e3e7e8572c4fea?d=identicon&s=25 Jeremy McAnally (Guest)
on 2006-12-22 03:38
(Received via mailing list)
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
Ce8b03e5750097942c58e12b46724312?d=identicon&s=25 Giles Bowkett (Guest)
on 2006-12-22 04:04
(Received via mailing list)
The online version of the first edition of Pickaxe has it here:

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

Scroll down to "Blocks and Iterators." It's about 2/3rds down the page.
918c6daad03c85e51ad1a11f57017947?d=identicon&s=25 Devin Mullins (twifkak)
on 2006-12-22 04:42
(Received via mailing list)
Giles Bowkett wrote:
> The online version of the first edition of Pickaxe has it here:
>
> http://www.rubycentral.com/book/intro.html
>
> 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#bl...

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
Bfab87df9f06c2a4ac1782e1fa794108?d=identicon&s=25 Sam'l B (Guest)
on 2006-12-22 07:34
(Received via mailing list)
dblack@wobblini.net wrote:
> David
>
	Got it!  Thanks!
Bfab87df9f06c2a4ac1782e1fa794108?d=identicon&s=25 Sam'l B (Guest)
on 2006-12-22 07:36
(Received via mailing list)
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
Bfab87df9f06c2a4ac1782e1fa794108?d=identicon&s=25 Sam'l B (Guest)
on 2006-12-22 07:42
(Received via mailing list)
Devin Mullins wrote:
>
> 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.
6238fa336682c61c5ec448f1ddb9455c?d=identicon&s=25 unknown (Guest)
on 2006-12-22 08:52
(Received via mailing list)
> or did I miss it somewhere?
>
> Sam Bassett
>
>


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

;-)

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

Richard W. Norton
This topic is locked and can not be replied to.