LoginSignup
32
16

More than 5 years have passed since last update.

[ruby]連番の配列を用意する

Posted at

参考:知って得する!55のRubyのトリビアな記法

こうすると、RangeクラスをArrayに入れてしまう。

[1..10] # => [1..10]

こうすると連番のArrayを用意できる。

[*1..10]
# => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[*'a'..'f']
# => ["a", "b", "c", "d", "e", "f"]
32
16
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
32
16