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 273
def DelegateClass(superclass)
klass = Class.new(Delegator)
methods = superclass.public_instance_methods(true)
methods -= ::Delegator.public_api
methods -= [:to_s,:inspect,:=~,:!~,:===]
klass.module_eval {
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
}
klass.module_eval do
methods.each do |method|
define_method(method, Delegator.delegating_block(method))
end
end
return klass
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.