Added main#define_method.

Fixes #2886.