Why use a lonely operator?

The lonely operator doesn't do much other than save you from typing an additional condition. Why use it? Well it makes sense to use it when you are dealing with a 3rd party object in your code that may or may not be present. e.g.

def print_circuit(stl_file, callback: nil)

  # print the circuit board
  @pcb.print stl_file
  # then notify something or someone through the callback when it as finished
  callback.pcb_done if callback

end

Here's where the lonely operator can be used:

def print_circuit(stl_file, callback: nil)

  # print the circuit board
  @pcb.print stl_file
  # then notify something or someone through the callback when it as finished
  callback&.pcb_done
  #=> nil

end

If the callback object is nil then no further action will be taken with it.

Note: The lonely operator was introduced in Ruby 2.3.