Andrew Stewart wrote:
> On 17 Jan 2008, at 16:21, Joshua Beall wrote:
> So if you look at your block again:
> 
>    do |format|
>      format.html
>      format.xml
>    end
> 
> ...and you imagine executing it as a method, the block variable,
> format, should look like a method argument.  Accordingly it is set to
> the responder object passed in by the line:
> 
>    block.call(responder)

Ok, I think I'm with you.  Correspondingly that would mean that I can 
replace this

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @posts }
    end

With this:

    responder = Responder.new(self)
    responder.html
    responder.xml { render :xml => @posts}
    responder.respond

And it should work.  And indeed it does.  However, there are still 
somethings I don't understand.  Why can't I do this?

    responder = Responder.new(self)
    responder.html
    responder.xml( { render :xml => @posts} )
    responder.respond

If I do that, I get the error (point to the line where I added 
parentheses):

posts_controller.rb:9: syntax error, unexpected tSYMBEG, expecting kDO 
or '{' or '('

It's complaining about the symbol :xml.

Second, from this line here:
http://dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/mime_responds.rb#L102

Can you help me understand this line:
block ||= lambda { |responder| types.each { |type| responder.send(type) 
} }

It looks like it would be overwriting the "block" parameter of the 
"respond_to" method -- and yet apparently it is not?
-- 
Posted via http://www.ruby-forum.com/.