Delegator is an abstract class used to build delegator pattern objects from subclasses. Subclasses should redefine _getobj_. For a concrete implementation, see SimpleDelegator.
Returns true if two objects are considered same.
# File delegate.rb, line 157 def ==(obj) return true if obj.equal?(self) self.__getobj__ == obj end
This method must be overridden by subclasses and should return the object method calls are being delegated to.
# File delegate.rb, line 166 def __getobj__ raise NotImplementedError, "need to define `__getobj__'" end
This method must be overridden by subclasses and change the object delegate to obj.
# File delegate.rb, line 174 def __setobj__(obj) raise NotImplementedError, "need to define `__setobj__'" end
Clone support for the object returned by _getobj_.
# File delegate.rb, line 188 def clone new = super new.__setobj__(__getobj__.clone) new end
Duplication support for the object returned by _getobj_.
# File delegate.rb, line 194 def dup new = super new.__setobj__(__getobj__.dup) new end
Serialization support for the object returned by _getobj_.
# File delegate.rb, line 179 def marshal_dump __getobj__ end
Reinitializes delegation from a serialized object.
# File delegate.rb, line 183 def marshal_load(obj) __setobj__(obj) end
Handles the magic of delegation through _getobj_.
# File delegate.rb, line 131 def method_missing(m, *args, &block) begin target = self.__getobj__ unless target.respond_to?(m) super(m, *args, &block) else target.__send__(m, *args, &block) end rescue Exception $@.delete_if{|s| %r"\A#{Regexp.quote(__FILE__)}:\d+:in `method_missing'\z"o =~ s} ::Kernel::raise end end
Checks for a method provided by this the delegate object by fowarding the call through _getobj_.
# File delegate.rb, line 149 def respond_to?(m, include_private = false) return true if super return self.__getobj__.respond_to?(m, include_private) end