Skip to content

devill/delegate-all

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

delegate-all

Automatically delegate method calls to another object.

The delegate_all function will define method_missing, responds_to? and public_methods so that any function present on the delegate class will be called if a message with the same name is recieved by the delegator class. This is a useful tool for implementing the state pattern, or as an aid during an inheritance to delegation refactor.

Example

class DelegatorClass
  delegate_all :delegate_object

  def initialize(delegate_object)
    @delegate_object = delegate_object
  end
end

class DelegateClass
  def delegated_method
  end
end

DelegatorClass.new(DelegateClass.new).delegated_method

In this case the delegate_all method call is equivalent to writing a delegator function with the name delegated_method and make it call the delegated_method on the DelegateClass

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages