class Decorator attr_reader :object # doctest: A Decorator should be initialized with thr decorated object. # >> object = Object.new # >> decorator = Decorator.new(object) # >> decorator.object == object # => true def initialize(object) @object = object end def method_missing(method, *args) @object.send(method, *args) end end class Class def decorator(decorator_class) old_new = self.method(:new) (class << self; self; end).send(:define_method, :new) do |*args| object = old_new.call(*args) decorator_class.new(object) end end end