class Delegator
   attr_accessor :delegate
   def operation
      if @delegate.respond_to?(:thing)
         @delegate.thing
      else
         'default implementation'
      end
   end
end

class Delegate
   def thing
      'delegate implementation'
   end
end

if __FILE__ == $PROGRAM_NAME

   
   a = Delegator.new
   puts a.operation 

   
   a.delegate = 'A delegate may be any object'
   puts a.operation 

   
   a.delegate = Delegate.new
   puts a.operation 
end