Questions tagged [splat]

The `*` operator as used in Ruby. So called because it looks like an insect that's splatted on a windscreen.

The * operator as used in Ruby. So called because it looks like an insect that's splatted on a windscreen.

166 questions
-10
votes
2 answers

How do I return the first string from a list or a string itself if it was passed instead of a list?

Ruby example of the mapping function I want: ["qwe", ["asd", "zxc"]].map{ |i| [*i][0] } => ["qwe", "asd"] def f array_or_string [*array_or_string].first end ["qwe", ["asd", "zxc"]].map &method(:f) => ["qwe", "asd"] f ["qwe", "zxc"] …
Nakilon
  • 34,866
  • 14
  • 107
  • 142
1 2 3
11
12