I wish to exit a before_save block. If I invoke return true in the before_save blockk, I get a return can''t jump across threads error return. Hitting the Pickaxe book, it says that returns from a block will cause this error. (Why? I don''t know.) So ... how does one exit gracefully from a block prior to falling off the end of the block? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ralph Shnelvar wrote:> I wish to exit a before_save block. If I invoke > > return true > > in the before_save blockk, I get a > > return can''t jump across threads > > error return. > > > Hitting the Pickaxe book, it says that returns from a block will cause > this error. (Why? I don''t know.Nor should you care.> > So ... how does one exit gracefully from a block prior to falling off > the end of the block?One doesn''t AFAIK. In the general case, you could use a conditional statement or raise an exception. In your case, I''d advise using a method callback instead of a block. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jan 30, 3:40 pm, Ralph Shnelvar <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hitting the Pickaxe book, it says that returns from a block will cause > this error. (Why? I don''t know.) > > So ... how does one exit gracefully from a block prior to falling off > the end of the block?def foo yield end foo { return 1; puts ''return''} #=> LocalJumpError: unexpected return foo { next 1; puts ''not reached''} #=> 1 Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.