Possible Duplicate:
What does !! mean in ruby?
I’m learning ruby/rails and found a tutorial with the following code example:
def role?(role)
return !!self.roles.find_by_name(role.to_s.camelize)
end
I don’t have any idea for what the !! do, neither the !!self do.
I really googled about that, but doesn’t find anything.
Can anyone give a short explanation? Thanks in advance.
It’s the “not” operator (
!) repeated twice, so that it’s argument will be coerced to its negated boolean and then its corresponding boolean. Basically, it’s a way to coerce any object into its boolean value.