A decorator vs. a subclass

In my most recent article, I mentioned a great new feature in Rails 5.1, delegate_missing_to. With delegate_missing_to, any method that you can’t find on one object is called on another object, instead:

1 2 3 4 5 6 7 8 9 10 11 12 13 class Player delegate_missing_to :@user def initalize(user) @user = user end def points Game.points_for_user(user.id) end end Player.new(user).name # calls user.name

But, like Gavin mentioned in the comments, this seems like an odd way to avoid inherita...

 •  0 comments  •  flag
Share on Twitter
Published on May 08, 2017 21:40
No comments have been added yet.