Splats are cool. They're not just for exploding arrays, although that is fun. They can also cast to Array and flatten arrays (See http://github.com/mischa/splat/tree/master for an exhaustive list of what they do.)
It looks like one cannot perform additional operations on the splat, but in 1.8.6/1.9 the following code throws "unexpected ...
Someone asked about the splat operator yesterday, and I wanted to see the source code... would that be written in C or in Ruby? Where would it be found?
...
match, text, number = *"foobar 123".match(/([A-z]*) ([0-9]*)/)
I know this is doing some kind of regular expression match but what role does the splat play here and is there a way to do this without the splat so it's less confusing?
...
fruit = ["apple","red","banana","yellow"]
=> ["apple", "red", "banana", "yellow"]
Hash[*fruit]
=> {"apple"=>"red", "banana"=>"yellow"}
Why does the splat cause the array to be so neatly parsed into the Hash?
Or, more precisely, how does the Hash "know" that "apple" is the key and "red" is its corresponding value?
Is it simply be...
Say I have a list of arguments:
> (setf format-args `(t "it's ~a" 1))
(T "it's ~a" 1)
How can I then "splat" or "unroll" this into a series of arguments rather than a single list argument, for supplying to the format function?
i.e I would like the following function call to take place:
> (format t "it's ~a" 1)
For reference, I wo...