> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# hookmetamethod

> Finds the named metamethod on a value and replaces that metamethod function with the provided replacement. The metamethod name must be a string and the replacement must be a function.

<div className="real-function-page">
  ```lua theme={null}
  hookmetamethod(object: any, metamethod: string, replacement: function): function
  ```

  ## Arguments

  <ParamField path={"object"} type={"any"} required>
    Value whose methods is inspected with raw metafield lookup.
  </ParamField>

  <ParamField path={"metamethod"} type={"string"} required>
    Metafield name passed to raw metafield lookup.
  </ParamField>

  <ParamField path={"replacement"} type={"function"} required>
    Function passed to hookfunction as the replacement for the found metamethod function.
  </ParamField>

  ## Returns

  <ResponseField name={"original"} type={"function"}>
    Cloned original metamethod closure returned by hookfunction.
  </ResponseField>

  ## Example

  Hook an existing metamethod function.

  ```lua theme={null}
  local object = setmetatable({}, {
      __index = function(_, key)
          return key
      end,
  })

  local original
  original = hookmetamethod(object, "__index", function(self, key)
      if key == "Name" then
          return "Real"
      end

      return original(self, key)
  end)
  ```
</div>
