Re: yields and blocks in Rails

David A. Black
Wed, 07 May 2008 21:09:50 -0000

HI --

On Wed, 7 May 2008, Charles wrote:

>
> The below code works just fine in Ruby but I get a LocalJumpError in
> Rails stating "no block given". I thought I knew what a block
was, but
> given the results, I am not so sure. Could someone please offer an
> explanation as to what is going on?
>
> Thanks,
> C.
>
>
> class Array
>  def comb(n = size)
>    if size < n or n < 0
>    elsif n == 0
>      yield([])
>    else
>      self[1..-1].comb(n) do |x|
>        yield(x)
>      end
>      self[1..-1].comb(n - 1) do |x|
>        yield([first] + x)
>      end
>    end
>  end
> end

Can you send a case where you''re calling it and it''s giving
you that
error?


David

--
Rails training from David A. Black and Ruby Power and Light:
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
   INTRO TO RAILS         June 24-27           London (Skills Matter)
See http://www.rubypal.com for details and updates!