Tutorial :Why does this code produce a nil following a Proc.call?


C:\>irb  irb(main):001:0> s = Proc.new { puts "Hello" }  => #<Proc:0x04051780@(irb):1>  irb(main):002:0> s.call  Hello  => nil  

What causes the nil?

ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]  


s does not return a value, As @sepp2k points out in the comment, puts returns nil, so nil automatically becomes the return value since that is the last statement in the proc.

It just gets printed to the terminal as the return value of the last statement, similar to that cryptic output after you assign the proc to s.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »