diff --git a/lib/naught/base_class_initializer.rb b/lib/naught/base_class_initializer.rb new file mode 100644 index 0000000..f705258 --- /dev/null +++ b/lib/naught/base_class_initializer.rb @@ -0,0 +1,29 @@ +module Naught + class BaseClassInitializer + attr_reader :builder, :base_class + + def initialize(builder) + @builder = builder + @base_class = builder.base_class + end + + def execute(generation_mod, customization_mod) + builder = @builder + Class.new(base_class) do + const_set :GeneratedMethods, generation_mod + const_set :Customizations, customization_mod + const_set :NULL_EQUIVS, builder.null_equivalents + include Conversions + remove_const :NULL_EQUIVS + Conversions.instance_methods.each do |instance_method| + undef_method(instance_method) + end + const_set :Conversions, Conversions + + include NullObjectTag + include generation_mod + include customization_mod + end + end + end +end diff --git a/lib/naught/null_class_builder.rb b/lib/naught/null_class_builder.rb index a137d09..522689b 100644 --- a/lib/naught/null_class_builder.rb +++ b/lib/naught/null_class_builder.rb @@ -1,5 +1,6 @@ require 'naught/basic_object' require 'naught/conversions' +require 'naught/base_class_initializer' module Naught class NullClassBuilder @@ -38,31 +39,18 @@ def generate_class respond_to_any_message unless interface_defined? generation_mod = Module.new customization_mod = customization_module # get a local binding - builder = self apply_operations(operations, generation_mod) - - null_class = Class.new(@base_class) do - const_set :GeneratedMethods, generation_mod - const_set :Customizations, customization_mod - const_set :NULL_EQUIVS, builder.null_equivalents - include Conversions - remove_const :NULL_EQUIVS - Conversions.instance_methods.each do |instance_method| - undef_method(instance_method) - end - const_set :Conversions, Conversions - - include NullObjectTag - include generation_mod - include customization_mod - end - + null_class = initialize_base_class(generation_mod, customization_mod) apply_operations(class_operations, null_class) null_class end + def initialize_base_class(generation_mod, customization_mod) + BaseClassInitializer.new(self).execute(generation_mod, customization_mod) + end + def method_missing(method_name, *args, &block) command_name = command_name_for_method(method_name) if Commands.const_defined?(command_name)