1
1

More than 1 year has passed since last update.

[Ruby] Stringクラスのinclude?メソッド

Posted at

学習したことのアウトプットとして

include?メソッド

Rubyの組み込みライブラリ
指定した値が含まれているかを判定するメソッド
指定した値が含まれている場合はtrueを、含まれていない場合はfalseを返り値として返す

Arrayのinclude?メソッドを使用する場合

指定した値が、配列中に含まれているかを判定する

a = [ "a", "b", "c" ]
a.include?("b")       #=> true
a.include?("z")       #=> false

Stringのinclude?メソッドを使用する場合

文字列中に部分文字列が含まれていれば真を返す

"hello".include? "lo"   #=> true
"hello".include? "ol"   #=> false
"hello".include? ?h     #=> true

※補足等がありましたらコメントいただけると幸いです

1
1
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
1
1