class T::InterfaceWrapper

def self.wrapped_dynamic_cast(obj, mod)

Parameters:
  • mod (Module) -- type to cast `obj` to
  • obj (Object) -- object to cast
def self.wrapped_dynamic_cast(obj, mod)
  # Avoid unwrapping and creating an equivalent wrapper.
  if obj.is_a?(T::InterfaceWrapper) && obj.__interface_mod_DO_NOT_USE == mod
    return obj
  end
  cast_obj = dynamic_cast(obj, mod)
  if cast_obj.nil?
    nil
  elsif cast_obj.class == mod
    # Nothing to wrap, they want the full class
    cast_obj
  else
    new(cast_obj, mod)
  end
end