3

Here is something I don't understand. Why is the first example not working (ArgumentError) but the second?

class FooController < ActionController::Base
  layout proc { request[:action] == 'index' ? 'foo' : false }
end

class FooController < ActionController::Base
  layout proc { |controller| request[:action] == 'index' ? 'foo' : false }
end

I'm creating a proc and NOT a lambda. And I always thought only lambdas require correct arguments.

Gets the block converted to a lambda somewhere?

Andy
  • 841
  • 2
  • 8
  • 15

1 Answers1

0

proc can also take args, at least, within layout method, it requires the request object, on the other hand, you can read When to use lambda, when to use Proc.new? to see what the difference is between proc and lambda.

Community
  • 1
  • 1
Richie Min
  • 654
  • 5
  • 15
  • Well, I know that procs can take arguments but my question was why do I get a ArgumentError. Because procs usually don't care about the number or arguments. `p = Proc.new {}; p.call(1)` – Andy Dec 13 '12 at 02:03
  • 2
    it not care about, proc can use none args, but in layout method, it requires argments – Richie Min Dec 13 '12 at 02:15