LoginSignup
0
0

More than 1 year has passed since last update.

【Ruby】putsの戻り値はnil

Posted at

rails consoleで以下のメソッドを試したところ混乱したので、備忘録として書き留めます。

$ rails c

?> def palindrome_tester(s)
?>   if s == s.reverse
?>     puts "palindrome"
?>   else
?>     puts "not palindrome"
?>   end
?> end 
=> :palindrome_tester

>> palindrome_tester("racecar")
palindrome
=> nil

>> palindrome_tester("asdfg")
not palindrome
=> nil

上記の"=> nil"の部分が毎回出力されるのが不明だったのですが、putsは文字列を出力した後、nilを返しているだけでした。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0