Parent

Naught::NullClassBuilder

Attributes

base_class[RW]
inspect_proc[RW]
interface_defined[RW]

Public Class Methods

new() click to toggle source
# 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
Also aliased as: get

Public Instance Methods

black_hole() click to toggle source

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
customization_module() click to toggle source
# File lib/naught/null_class_builder.rb, line 29
def customization_module
  @customization_module ||= Module.new
end
customize(&customization_block) click to toggle source
# 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
defer(options = {}, &deferred_operation) click to toggle source
# 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
generate_class() click to toggle source
# 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
interface_defined?() click to toggle source
# File lib/naught/null_class_builder.rb, line 20
def interface_defined?
  !!@interface_defined
end
method_missing(method_name, *args, &block) click to toggle source
# 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
null_equivalents() click to toggle source
# File lib/naught/null_class_builder.rb, line 33
def null_equivalents
  @null_equivalents ||= [nil]
end
respond_to?(method_name, include_private = false) click to toggle source
# 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
respond_to_any_message() click to toggle source
# 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
respond_to_missing?(method_name, include_private = false) click to toggle source
# 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
stub_method(subject, name) click to toggle source
# File lib/naught/null_class_builder.rb, line 123
def stub_method(subject, name)
  send(@stub_strategy, subject, name)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.