0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ruby・putsの戻り値はnilになる

Posted at

まず、メソッド palindrome_tester を定義する。

def palindrome_tester(s)
  if s == s.reverse
   puts "It`s a palindrome!"
  else
   puts "It`s not a palindrome."
  end
 end

メソッドpalindrome_tester を実行する。

puts palindrome_tester("racecar")
It`s a palindrome!

=> nil

戻り値としては nil が表示されている。

「It`s a palindrome!」という文言は、コンソールの標準出力であり、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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?