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]
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]
As @sepp2k points out in the comment, s
does not return a value,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
.