From: Justin Collins Date: 2008-01-18T10:41:23+09:00 Subject: Re: Ruby syntax in "respond_to do |format| line -- can clari Joshua Beall wrote: > Justin Collins wrote: > >> Joshua Beall wrote: >> >>>> ...and you imagine executing it as a method, the block variable, >>>> >>> format.html # index.html.erb >>> And it should work. And indeed it does. However, there are still >>> posts_controller.rb:9: syntax error, unexpected tSYMBEG, expecting kDO >>> or '{' or '(' >>> >>> It's complaining about the symbol :xml. >>> >>> >> In this case { render :xml => @posts} is being interpreted as a Hash, >> not a block and that is messing things up for you. >> > > So how do I construct the method call so that I can use parentheses? > There is really no reason to do so in most cases, but you can if you really want: responder = Responder.new(self) responder.html l = lambda { render :xml => @posts} responder.xml(&l) responder.respond The "&" (in this case) says "make this the block that gets passed to the method." I believe you could also do: responder.xml(&lambda { render :xml => @posts } ) or responder.xml(&Proc.new { render :xml => @posts } ) But, again, this is not the normal way to do it. You can sort of tell, because it is much more awkward than responder.xml { render :xml => @posts } Hope that helps some. -Justin