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?
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.
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?
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.
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
--
Q. What's a good holiday present for the serious Rails developer?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black\)
aka The Ruby book for Rails developers!
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
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.
>
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.
>