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 3 years have passed since last update.

[Ruby] Array#include?メソッド

Posted at

##はじめに
今回はinclude?メソッドについて紹介します。同じincludeでも、Rubyの中ではいくつかのincludeがあるのですが、この記事では配列に対して使うinclude?を説明します。

##Array#include?

配列に対して使用します。配列の中にある要素があるのかどうかを調べるためのメソッドです。その調べたい要素はinclude?に引数として渡します。
あったらtrue、なかったらfalseを返します。

array = [1, 2, 3, 4, 5]
array.include?(3)
=> true

array.include?(6)
=> false

使用するオブジェクトが配列であれば調べたい要素のデータの型が数値だろうが文字列だろうが問題ありません。

array = ["a", "b", "c", "d"]
array.include?("c")
=> true

array.include?("e")
=> false
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?