class JsDuck::Util::NullObject
A class that does nothing. Responds to all methods by returning self, unless a hash passed to constructor. See: en.wikipedia.org/wiki/Null_Object_pattern
Public Class Methods
new(methods={})
click to toggle source
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.
# File lib/jsduck/util/null_object.rb, line 13 def initialize(methods={}) @methods = methods end
Public Instance Methods
method_missing(meth, *args, &block)
click to toggle source
# File lib/jsduck/util/null_object.rb, line 17 def method_missing(meth, *args, &block) if @methods.has_key?(meth) value = @methods[meth] if value.respond_to?(:call) value.call(*args, &block) else value end else self end end
respond_to?(meth)
click to toggle source
# File lib/jsduck/util/null_object.rb, line 30 def respond_to?(meth) @methods.has_key?(meth) end