0

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?

Amin Shah Gilani
  • 8,675
  • 5
  • 37
  • 79

1 Answers1

1

The question mark prefix produces a single character; the one you write right after it.

Raffael
  • 2,639
  • 16
  • 15