Sha256: 9b5d7b067d819e6bd05cca90f01ecef8e57c128f3f4e737519862e4a8aca9c10

Contents?: true

Size: 641 Bytes

Versions: 31

Compression:

Stored size: 641 Bytes

Contents

module JsDuck
  # 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

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
jsduck-4.0.1 lib/jsduck/null_object.rb
jsduck-4.0.0 lib/jsduck/null_object.rb
jsduck-3.11.2 lib/jsduck/null_object.rb
jsduck-4.0.beta2 lib/jsduck/null_object.rb
jsduck-3.11.1 lib/jsduck/null_object.rb
jsduck-4.0.beta lib/jsduck/null_object.rb
jsduck-3.11.0 lib/jsduck/null_object.rb
jsduck-3.10.5 lib/jsduck/null_object.rb
jsduck-3.10.4 lib/jsduck/null_object.rb
jsduck-3.10.3 lib/jsduck/null_object.rb
jsduck-3.10.2 lib/jsduck/null_object.rb
jsduck-3.10.1 lib/jsduck/null_object.rb
jsduck-3.10.0 lib/jsduck/null_object.rb
jsduck-3.9.1 lib/jsduck/null_object.rb
jsduck-3.9.0 lib/jsduck/null_object.rb
jsduck-3.9.0.pre lib/jsduck/null_object.rb
jsduck-3.8.4 lib/jsduck/null_object.rb
jsduck-3.8.3 lib/jsduck/null_object.rb
jsduck-3.8.2 lib/jsduck/null_object.rb
jsduck-3.8.1 lib/jsduck/null_object.rb