この話はRuby 1.8.6を前提としています。 先日「[PHP]echoとprintの違いを再確認」というエントリで、echoとprintの違いを確認したばかりですが、折角なのでRubyのputsとprintの違いも確認してみようと思います。 ・どちらもRubyの組み込み関数 ・括弧で括っても括らなくても使える ※注釈1 ○ puts 'hoge'; ○ print 'hoge'; ○ puts ('hoge'); ○ print ('hoge'); ・どちらも返り値は常に「nil」を返す ・どちらも複数のパラメータを渡せる ○ puts 'hoge', a, 'fuga' ○ print 'hoge', a, 'fuga' ○ puts ('hoge', a, 'fuga') ○ print ('hoge', a, 'fuga') ・putsのみ引数を出力した後、続けて改行を出力する