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 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 > endCan 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! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I was trying to run it in some controller code. I gave up trying to do anything fancy and just focused on getting something simple to run. The exception name in the header is LocalJumpError, and the error message in the box is "no block given". I placed the array extension as the first thing in the controller file before the controller class. I call the sample below from within a method in the controller class. [''a'',''b'',''c'',''d''].comb(3).each do |element| puts element end here is where it points to the errors: app/controllers/courses_controller.rb:11:in `comb'' app/controllers/courses_controller.rb:11:in `comb'' app/controllers/courses_controller.rb:5:in `comb'' app/controllers/courses_controller.rb:10:in `comb'' Because it is the first thing in the file, the line numbers will add up with the previous code example. They point to the yields. thanks, C. On May 7, 5:09 pm, "David A. Black" <dbl...-0o/XNnkTkwhBDgjK7y7TUQ@public.gmane.org> wrote:> 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) > Seehttp://www.rubypal.comfor details and updates!--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Charles wrote:> [''a'',''b'',''c'',''d''].comb(3).each do |element| > puts element > endYou should get a LocalJumpError with this code in Ruby, too. Remove the ".each" and it should be ok. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the eyes :) with the array output, i was tacking on a .each without even thinking about it. Comparing the ruby code, i completely glossed over the .each . I appreciate it! C. On May 8, 3:54 am, Mark Bush <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Charles wrote: > > [''a'',''b'',''c'',''d''].comb(3).each do |element| > > puts element > > end > > You should get a LocalJumpError with this code in Ruby, too. Remove the > ".each" and it should be ok. > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---