I recently came across this code that calculates "4 * n!"
def moreThanUsual n
eval [*1..n, 4] * ?*
# 4 * Math.gamma(n + 1)
end
which made me interested in the ?*
, and upon experimentation I saw:
>> ?*
=> "*"
>> ?a
=> "a"
>> ?1
=> "1"
>> ?8
=> "8"
>> ?83
SyntaxError: (irb):32: syntax error, unexpected '?'
from /usr/local/bin/irb:11:in `<main>'
>> ?ab
SyntaxError: (irb):33: syntax error, unexpected '?'
from /usr/local/bin/irb:11:in `<main>'
What is this strange operator that only takes one proceeding characterright against it, and changes it into a string?