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 ?や!のついたメソッドの使い方

Last updated at Posted at 2019-10-31

!

  • upcase
  • 文字列を大文字で返すメソッド
name = "sasaki"
puts name.upcase    
puts name

実行結果:SASAKI

  • upcase!
  • 文字列を大文字で返しつつ、元の文字列も大文字に書き換えるメソッド
  • 破壊的なメソッド
puts name.upcase!
puts name

実行結果:
SASAKI
SASAKI

※もし小文字として使用したいなら戻す必要あり

  • downcase
  • 文字列を小文字で返すメソッド
name = "SASAKI"
puts name.downcase

実行結果:sasaki

  • reverse
  • 文字列を逆順に返すメソッド
name1 = "sasaki"
puts name1.reverse

実行結果:ikasas

?

  • 真偽値 true false
p name1.empty?  #nameの中身が空かどうか
p name1.include?("")  #nameの中に"k"が含まれているかどうか

実行結果:
false
true

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?