Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more
BasicObject
The primary interface to this library. Use to setup delegation when defining your class.
class MyClass < DelegateClass( ClassToDelegateTo ) # Step 1 def initialize super(obj_of_ClassToDelegateTo) # Step 2 end end
# File delegate.rb, line 356 def DelegateClass(superclass) klass = Class.new(Delegator) methods = superclass.instance_methods methods -= ::Delegator.public_api methods -= [:to_s,:inspect,:=~,:!~,:===] klass.module_eval do def __getobj__ # :nodoc: @delegate_dc_obj end def __setobj__(obj) # :nodoc: raise ArgumentError, "cannot delegate to self" if self.equal?(obj) @delegate_dc_obj = obj end methods.each do |method| define_method(method, Delegator.delegating_block(method)) end end klass.define_singleton_method :public_instance_methods do |all=true| super(all) - superclass.protected_instance_methods end klass.define_singleton_method :protected_instance_methods do |all=true| super(all) | superclass.protected_instance_methods end return klass end