Object
# File lib/naught/null_class_builder.rb, line 12 def initialize @interface_defined = false @base_class = Naught::BasicObject @inspect_proc = lambda { '<null>' } @stub_strategy = :stub_method_returning_nil define_basic_methods end
Builder API
See also the contents of lib/naught/null_class_builder/commands
# File lib/naught/null_class_builder.rb, line 98 def black_hole @stub_strategy = :stub_method_returning_self end
# File lib/naught/null_class_builder.rb, line 29 def customization_module @customization_module ||= Module.new end
# File lib/naught/null_class_builder.rb, line 24 def customize(&customization_block) return unless customization_block customization_module.module_exec(self, &customization_block) end
# File lib/naught/null_class_builder.rb, line 114 def defer(options = {}, &deferred_operation) list = options[:class] ? class_operations : operations if options[:prepend] list.unshift(deferred_operation) else list << deferred_operation end end
# File lib/naught/null_class_builder.rb, line 37 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 apply_operations(class_operations, null_class) null_class end
# File lib/naught/null_class_builder.rb, line 20 def interface_defined? !!@interface_defined end
# File lib/naught/null_class_builder.rb, line 66 def method_missing(method_name, *args, &block) command_name = command_name_for_method(method_name) if Commands.const_defined?(command_name) command_class = Commands.const_get(command_name) command_class.new(self, *args, &block).call else super end end
# File lib/naught/null_class_builder.rb, line 33 def null_equivalents @null_equivalents ||= [nil] end
# File lib/naught/null_class_builder.rb, line 84 def respond_to?(method_name, include_private = false) command_name = command_name_for_method(method_name) Commands.const_defined?(command_name) || super rescue NameError super end
# File lib/naught/null_class_builder.rb, line 102 def respond_to_any_message defer(:prepend => true) do |subject| subject.module_eval do def respond_to?(*) true end end stub_method(subject, :method_missing) end @interface_defined = true end
# File lib/naught/null_class_builder.rb, line 77 def respond_to_missing?(method_name, include_private = false) command_name = command_name_for_method(method_name) Commands.const_defined?(command_name) || super rescue NameError super end
Generated with the Darkfish Rdoc Generator 2.