Refactoring Generators::Base.

The defaults hash isn't used unless the +class_options+ hash has a
particular key, so we don't need to compute it unless this is true.

Also moving some code for extracting a module into its own method.
Merge pull request #12061 from wangjohn/refactoring_generators_base

Refactoring Generators::Base.