Programming Ruby: Chapter 7

  • if can be used to build expressions, so you can use it for conditional assignments.
    variable =
      if condition
        if_value
      else
        else_value
  • Even using operators is basically calling methods. So 3 * 2 + 1 can be written as 3.*(2).+(1).
  • After overriding bultin operators, the originals are still accesible through Kernel.name_of_overridden_operator.
  • Aliases for methods are created with alias.
  • The value-setting methods whose names end with an equals sign always return the value of the passed-in parameter.
  • The defined? operator does not simply return a boolean value telling you whether its parameter is defined or not, it actually describes the type of the parameters’ value, e.g. "expression" or "method".
  • Single-line if-statements need the then-keyword.
  • A colon may be used instead of the then-keyword.
  • You can use objects of your own classes in case-statements if you provide a sensible === method.

 

Leave a Reply