small medium large xlarge

21 Sep 2011, 17:18
T.J. Zeeman (2 posts)

While working on the atom.builder part of generating a feed, the next snippet confused me a bit: do |author|

Given the label author of the first line I expected this to be used to invoke the name and email methods, but instead they were invoked on the entry itself. Strangely enough this code does seem to be working.

I’ve also tried the code I expected: do |author|

and this works as well.

I’m a bit confused what is supposed to be the correct piece now. The first (taken from the book)? If so, then why does it have that seemingly unused author part in it? The second? If so, then why does the first one work as well?
21 Sep 2011, 20:02
Sam Ruby (633 posts)

Good catch. |author| is clearly unnecessary, and should be removed from the book.

As you are curious, I encourage you to explore builder. entry is a Builder::XmlMarkup object. If you follow the preceding link, you will find the following text:

the markup block now gets the markup object sent as an argument, allowing you to use a shorter alias within the block.

In this case, author isn’t shorter than entry, but it becomes an alias for the markup object anyway. :-)

You must be logged in to comment