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