Module: Tins::Write

Included in:
IO
Defined in:
lib/tins/write.rb

Overview

Tins::Write provides secure write functionality that can be extended onto modules/classes to add a ‘write` method.

When a module is extended with Tins::Write, it will:

  • Extend the module with SecureWrite methods

  • Conditionally alias ‘secure_write` to `write` if no existing `write` method exists

  • Issue a warning if ‘write` already exists (when $DEBUG is enabled)

Class Method Summary collapse

Class Method Details

.extended(modul) ⇒ Object

Called when Tins::Write is extended onto a module. Extends the receiving module with SecureWrite functionality and conditionally aliases secure_write to write.

Parameters:

  • modul (Module)

    The module being extended



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tins/write.rb', line 17

def self.extended(modul)
  modul.extend SecureWrite
  if modul.respond_to?(:write)
    $DEBUG and warn "Skipping inclusion of Tins::Write#write method, "\
      "include Tins::Write::SecureWrite#secure_write instead"
  else
    class << modul; self; end.instance_eval do
      alias_method :write, :secure_write
    end
  end
  super
end