tags:

views:

52

answers:

1
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]
+3  A: 

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.

Mark Rushakoff
More accurately: s returns the value that is returned by puts and puts returns nil.
sepp2k
I haven't used Ruby much, I was just going by paradigms from other languages. Thanks and answer updated.
Mark Rushakoff