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) b.to_s #=> "HELLO" c = 10 b.become(c) b.to_s #=> "10"
TODO: Use BasicObject for Ruby 1.9.
# File lib/supplemental/facets/reference.rb, line 51 def self.new(obj) ref = allocate ref.become obj ref end
# File lib/supplemental/facets/reference.rb, line 67 def __value__ @ref end
# File lib/supplemental/facets/reference.rb, line 61 def become(obj) old = @ref @ref = obj old end
# File lib/supplemental/facets/reference.rb, line 57 def method_missing(*args, &block) @ref.__send__(*args, &block) end