LoginSignup
0
0

More than 5 years have passed since last update.

[Ruby] Rangeオブジェクトについて

Last updated at Posted at 2018-08-17

Rangeオブジェクト

rangeを作成


1..3
# 1..3

(1..3).class
# Range

to_aで変換してみるとどんなものかわかりやすい


(1..3).to_a
# [1, 2, 3]

..だと書いた通りの範囲を表す、...だと最後の数字は含まないRangeを返す


(1..3).to_a
# [1, 2, 3]

(1...3).to_a
# [1, 2]

アルファベットの並びを作ることもできる


('a'..'z').to_a
# ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
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