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
- #clone ⇒ Object
-
#copy ⇒ Object
(also: #deep_copy)
if object/copy has been required?.
- #dup ⇒ Object
Instance Method Details
#clone ⇒ Object
63 64 65 |
# File 'lib/mega/notcopyable.rb', line 63 def clone raise TypeError, "Object not copyable" end |
#copy ⇒ Object Also known as: deep_copy
if object/copy has been required?
70 71 72 |
# File 'lib/mega/notcopyable.rb', line 70 def copy raise TypeError, "Object not copyable" end |
#dup ⇒ Object
66 67 68 |
# File 'lib/mega/notcopyable.rb', line 66 def dup raise TypeError, "Object not copyable" end |