some fancy Ruby code to generalize things