lib/more/facets/reference.rb in facets-2.8.4 vs lib/more/facets/reference.rb in facets-2.9.0.pre.1
- old
+ new
@@ -5,14 +5,14 @@
#
# == Synopsis
#
# a = "HELLO"
# b = ref(a)
-# puts b #=> "HELLO"
+# b.to_s #=> "HELLO"
# c = 10
# b.become(c)
-# puts b #=> "10"
+# b.to_s #=> "10"
#
# == Authors
#
# * Thomas Sawyer
#
@@ -34,19 +34,20 @@
# Reference provides a way to access object indirectly.
# This allows for the object itself to be changed on the fly.
#
# a = "HELLO"
# b = ref(a)
-# puts b #=> "HELLO"
+# b.to_s #=> "HELLO"
# c = 10
# b.become(c)
-# puts b #=> "10"
+# b.to_s #=> "10"
#
-class Reference
+# TODO: Use BasicObject for Ruby 1.9.
- # Privatize most Kernel methods.
+class Reference #< BasicObject
+ # Privatize most Kernel methods.
private *instance_methods
def self.new(obj)
ref = allocate
ref.become obj
@@ -72,28 +73,11 @@
module Kernel
# Shortcut reference constructor.
-
def ref(x)
Reference.new(x)
end
end
-
-
-# _____ _
-# |_ _|__ ___| |_
-# | |/ _ \/ __| __|
-# | | __/\__ \ |_
-# |_|\___||___/\__|
-#
-
-=begin #test
-
- require 'test/unit'
-
- # TODO
-
-=end