LoginSignup
24
19

More than 5 years have passed since last update.

splat での Array 式展開

Posted at
[*0...5] #=> [0, 1, 2, 3, 4]

スター (*) での式展開はよく知られてるけど、この式展開は to_a が定義されているオブジェクトならなんにでも使えることを知った。

[23] pry(main)> String.class_eval { def to_a; self.split(''); end }
=> nil
[24] pry(main)> [*'abcde']
=> ["a", "b", "c", "d", "e"]
24
19
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
24
19