Sha256: f9a93b1b85e3242bde8792d90f12a219dae694783c6d82b084dd347cdb8160c4

Contents?: true

Size: 695 Bytes

Versions: 36

Compression:

Stored size: 695 Bytes

Contents

module JsDuck
  module Util

    # A class that does nothing.
    # Responds to all methods by returning self, unless a hash passed to
    # constructor.
    # See: http://en.wikipedia.org/wiki/Null_Object_pattern
    class NullObject
      # Optionally takes a hash of method_name => return_value pairs,
      # making it return those values for those methods, sort of like
      # OpenStruct, but for all other methods self is still returned and
      # any number of arguments is accepted.
      def initialize(methods={})
        @methods = methods
      end

      def method_missing(meth, *args, &block)
        @methods.has_key?(meth) ? @methods[meth] : self
      end
    end

  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
jsduck-5.3.4 lib/jsduck/util/null_object.rb
jsduck-5.3.3 lib/jsduck/util/null_object.rb
jsduck-5.3.2 lib/jsduck/util/null_object.rb
jsduck-5.3.1 lib/jsduck/util/null_object.rb
jsduck-5.3.0 lib/jsduck/util/null_object.rb
jsduck-5.2.0 lib/jsduck/util/null_object.rb
jsduck-5.1.0 lib/jsduck/util/null_object.rb
jsduck-5.0.1 lib/jsduck/util/null_object.rb
jsduck-5.0.0 lib/jsduck/util/null_object.rb
jsduck-5.0.0.beta5 lib/jsduck/util/null_object.rb
jsduck-5.0.0.beta4 lib/jsduck/util/null_object.rb
jsduck-4.10.4 lib/jsduck/util/null_object.rb
jsduck-5.0.0.beta3 lib/jsduck/util/null_object.rb
jsduck-4.10.3 lib/jsduck/util/null_object.rb
jsduck-4.10.2 lib/jsduck/util/null_object.rb
jsduck-4.10.1 lib/jsduck/util/null_object.rb
jsduck-4.10.0 lib/jsduck/util/null_object.rb
jsduck-4.9.0 lib/jsduck/util/null_object.rb
jsduck-4.8.0 lib/jsduck/util/null_object.rb
jsduck-5.0.0.beta2 lib/jsduck/util/null_object.rb