lib/singleton.rb in singleton-0.1.0 vs lib/singleton.rb in singleton-0.1.1

- old
+ new

@@ -11,11 +11,11 @@ # # ... # end # # This ensures that only one instance of Klass can be created. # -# a,b = Klass.instance, Klass.instance +# a,b = Klass.instance, Klass.instance # # a == b # # => true # # Klass.new @@ -56,14 +56,13 @@ # cloning or duping. # # == Singleton and Marshal # # By default Singleton's #_dump(depth) returns the empty string. Marshalling by -# default will strip state information, e.g. instance variables and taint -# state, from the instance. Classes using Singleton can provide custom -# _load(str) and _dump(depth) methods to retain some of the previous state of -# the instance. +# default will strip state information, e.g. instance variables from the instance. +# Classes using Singleton can provide custom _load(str) and _dump(depth) methods +# to retain some of the previous state of the instance. # # require 'singleton' # # class Example # include Singleton @@ -80,11 +79,10 @@ # end # # a = Example.instance # a.keep = "keep this" # a.strip = "get rid of this" -# a.taint # # stored_state = Marshal.dump(a) # # a.keep = nil # a.strip = nil @@ -92,9 +90,11 @@ # p a == b # => true # p a.keep # => "keep this" # p a.strip # => nil # module Singleton + VERSION = "0.1.1" + # Raises a TypeError to prevent cloning. def clone raise TypeError, "can't clone instance of singleton #{self.class}" end