From: Nikolai Weibull Date: 2011-01-20T19:21:33+09:00 Subject: [ruby-core:34653] Re: Returning from the callee On Thu, Jan 20, 2011 at 02:00, Rodrigo Rosenfeld Rosas wrote: > Sometimes it is useful to be able to return from the callee method. For > instance, consider a web application (how innovative, this is, right?): > def update > ������ @m = Model.find(params[:id]) > ������ @m.attributes = params[:model] > ������ render text: 'invalid' unless @m.valid? > ������ render text: 'valid' > end > > The experienced Rails user will know this will raise a DoubleRenderError > exception (in Grails it would be worse, since no exception would be raised > but the results would be concatenated). > > That is because, although we expect that "render" is the last thing to > happen while dealing with web requests, render cannot return from the callee > currently in Ruby. I guess Rails would implement it that way if this was > allowed in Ruby. Can you please provide a more elaborate example? I can���t deduce the value of your proposal from it. Your example is just a convoluted version of def update ��� render text: @m.valid? ? 'valid' : 'invalid' end (It���s not very localization-friendly either, but that���s another story ;-). (And, as already suggested, non-local exits are probably better controlled with catch/throw.)