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]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As @sepp2k points out in the comment,sdoes not return a value,putsreturnsnil, sonilautomatically 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.