1
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 2018-11-19

範囲リテラル範囲式「..」と「...」の違い

(1..5).to_a        #1から5以下の範囲
=> [1, 2, 3, 4, 5]
(1...5).to_a       #1から5未満の範囲
=> [1, 2, 3, 4]

後ろの数字(あるいは文字)を含むか、含まないか、そんだけ。

おまけ 〜範囲に含まれているかの確認〜 

(1..5).include?(5)
=> true
(1...5).include?(5)
=> false
(1..5) === 5
=> true
(1...5) === 5
=> false

範囲リテラル範囲式」こんなかんじ。

1
0
2

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