I found out this morning that proc.new works in the class initialization method, but not lambda. Specifically, I mean:
class TestClass attr_reader :proc, :lambda def initialize @proc = Proc.new {puts "Hello from Proc"} @lambda = lambda {puts "Hello from lambda"} end end c = TestClass.new c.proc.call c.lambda.call
In the above case, the result would be:
Hello from Proc test.rb:14:in `<main>': undefined method `call' for nil:NilClass (NoMethodError)
Why is this?
Thanks!
source share