From: Josh Cheek Date: 2010-10-23T16:12:23+09:00 Subject: Re: Why no yield in 1.9.2 blocks? --00163645800ab5932a049343673c Content-Type: text/plain; charset=ISO-8859-1 On Fri, Oct 22, 2010 at 3:09 PM, Ed Howland wrote: > Hi, > > I searched in vain for the answer, but why doesn't yield work inside > Ruby 192 blocks. The syntax allows you to pass the blocks as a &blk > param, but you have to call the block with blk.call. If you try to use > yield, you get a LocalJumpError: > > I always figured it was because it was enclosing its environment, and having yield in the block and the environment could bet ambiguous. def sort_proxy(collection) collection.sort! do |a,b| yield a , b # yield in a block end end ary = [4,2,9,3,1] sort_proxy ary do |a,b| a <=> b end ary # => [1, 2, 3, 4, 9] --00163645800ab5932a049343673c--