yields and blocks in Rails

Charles
Wed, 07 May 2008 19:37:35 -0000

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