I was poking through the Rails code today and stumbled upon this snippet:
new_date(*::Date._parse(string, false).values_at(:year, :mon, :mday))
What does the asterisk-double-colon (or splat-double-colon if you will) in *::Date
do?
Presumably it has something to do with the scope of a particularly-namespaced Date
class... but it's necessary enough for the author to include it rather than just use the standard Date
class.
I was reading the code wrong; it's not a "*::" operator at all.
Here's what's happening:
Date
class in the global scope (::Date
)_parse()
to get a hash of valuesvalues_at
to turn the hash into an arraynew_date()
, passing the array elements in for its year
, mon
, and mday
arguments.The lack of space between the *
and ::
operators made it confusing. :-\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With