Delegation Pattern in Ruby
Blog » Delegation Pattern in Ruby
Posted on 1249426208|%A: %d %B, %Y|agohover
Sometimes I need to pass an object to an API. But my object does not have the required methods…. And I don't want go and change the 3rd party class definition of my object. In Ruby the solution is easy. Another scenario is I have classes that do parts of the job required. And you need to combine them. There are many ways of implementing the delegation pattern in Ruby:
class Whatever delegate :first_name, :last_name, :to => :@user def initialize(user) @user = user end end
If you like this page, please spread the word:
As well as commenting here, you can tweet or email to me
Add a new comment







