#-- # Reference # # Copyright (c) 2005 Thomas Sawyer # # Ruby License # # This module is free software. You may use, modify, and/or redistribute this # software under the same terms as Ruby. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. # # ========================================================================== # Revision History # ========================================================================== # 2005.06.12 trans # Changed name from Ref to Reference. # ========================================================================== #++ require 'blankslate' #:title: Reference # # TODO # # == Synopsis # # a = "Hello" # b = ref(a) # b.upcase #=> "HELLO" # class Reference < BlankSlate def self.new(obj) ref = allocate ref.become obj ref end def method_missing(*args, &block) @ref.__send__(*args, &block) end def become(obj) old = @ref @ref = obj old end def __value__ @ref end alias_method :self, __value__ end module Kernel def ref(x) Reference.new(x) end end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # # TODO =begin #testing require 'test/unit' =end