Revert "Revert "Merge pull request #9206 from ranjaykrishna/use_define_method""

This reverts commit 8aa4603a5adaa56c818a7bd1c0b761b4ecca3d3e.

Reverting the revert because I reverted the wrong thing! Fail.