Module: DataRedactor::Refinements

Defined in:
lib/data_redactor/refinements.rb

Overview

Opt-in refinements that add a ‘#redact` method to `String`, `Hash`, and `Array` as sugar over redact / redact_deep.

Refinements are lexically scoped: ‘#redact` exists only in files that `using DataRedactor::Refinements`, so loading this file never pollutes the core classes globally. Apps that don’t opt in are unaffected, and there is no collision risk with other libraries’ ‘String#redact`.

‘DataRedactor.redact` remains the primary API; this is convenience only.

Examples:

require "data_redactor/refinements"
using DataRedactor::Refinements

"email alice@example.com".redact            #=> "email [REDACTED]"
{ token: "AKIAIOSFODNN7EXAMPLE" }.redact    #=> { token: "[REDACTED]" }
chat.ask(user_input.redact)                 # scrub before sending to an LLM