Only clean GEM_ENV/GEM_HOME when actually needed.

See #2915 for more information.
Detect tools before cleaning in ./configure

Previously this script would first try to run `ruby -S rake clean`. The `rake`
command here was pulled from the `@rake` instance variable. Due to this
variable not being set by default at this point the resulting command would be
`ruby -S clean` instead, resulting in a load error.

This commit fixes this by first checking the tools used and *then* running a
clean.

This fixes #2915.
Added specs on main#define_method.
Added main#define_method.
Merge pull request #2921 from razielgn/main-define_method

Added main#define_method.