Saturday, 24 August 2013

What does the ? operator do in Ruby

What does the ? operator do in Ruby

I have a function here that checks to see if the last element of an input
array is a hash table. If so, it'll remove the last element in the Hash
Table. This is from the solution in Ruby Monk section 6.2.
def remove_last(*arguments)
options = arguments[-1].is_a?(Hash) ? arguments.pop : {}
end
Whats does the '?' operator do between ...(Hash) ? arguments.pop ...
Why is there a ' : {} ' after arguments.pop as well.

No comments:

Post a Comment