Module: NotCopyable

Defined in:
lib/mega/notcopyable.rb

Overview

:title: NotCopyable

Disable copying via dup and clone (and copy).

Usage

require 'carat/notcopyable.rb'

Class FixedString < String
  include NotCopyable
end

s = FixedString.new("Don't tred on me!")
puts s
s2 = s.dup

produces

Don't tred on me!
TypeError, "Object not copyable"

Notes

  • I don’t think this will prove very useful, but just in case here it is.

Author(s)

  • Paul Brannan <paul at atdesk.com>

  • Thomas Sawyer

Instance Method Summary collapse

Instance Method Details

#cloneObject

Raises:

  • (TypeError)


63
64
65
# File 'lib/mega/notcopyable.rb', line 63

def clone
  raise TypeError, "Object not copyable"
end

#copyObject Also known as: deep_copy

if object/copy has been required?

Raises:

  • (TypeError)


70
71
72
# File 'lib/mega/notcopyable.rb', line 70

def copy
  raise TypeError, "Object not copyable"
end

#dupObject

Raises:

  • (TypeError)


66
67
68
# File 'lib/mega/notcopyable.rb', line 66

def dup
  raise TypeError, "Object not copyable"
end