Search code examples
rubycomputer-science

What object-type / class is the keyword "if"?


If the words true and false are Boolean's, and anything within quotes are String's ("hey"), what object-type / class / etc. is if, elsif, unless?

This question isn't specific to Ruby necessarily, although I am more familiar with Ruby's syntax.


Solution

  • if is a Control Expression (and less specifically a keyword).

    These are language level constructs that steer the flow of a program and like the other control structures in Ruby (else, elsif, case, etc) if cannot be be passed and it's value is the result of evaluating the expression.

    It doesn't have a type or class as it's not a value.