Change how define_method is used to support ruby 2.1.1

Closes #2177