That's right, as Namida has already mentioned, Ruby interprets
2.to_s *2
a
2.to_s(*2)
as parentheses in method calls are optional in Ruby. Asterisk is the so-called splat operator .
The only mysterious question: why *2 is evaluated as 2 . When you use it outside of a method call, the splat operator forces everything to an array, so
a = *2
will cause a to be [2] . In a method call, the splat operator does the opposite: decompresses something as a series of method arguments. Pass it an array of three elements, this will be the result in the form of three method arguments. Pass it a scalar value, it will just be redirected as one parameter. In this way,
2.to_s *2
essentially coincides with
2.to_s(2)
source share