From: Eric Mahurin Date: 2005-05-09T06:27:37+09:00 Subject: [ANN] reference 0.5 (was Re: object reference handle (like perl's reference to scalar)) I just released the code that has already been discussed here in gem form. Assuming you already have rubygems, you should be able to do "gem install reference" and then this in your ruby code: require 'rubygems' require_gem 'reference' Here are the examples I have in the embedded docs to give you an idea of all the ways you can make and use references: a = ("a".."h").to_a # ["a", "b", "c", "d", "e", "f", "g", "h"] b = a # b and a have the same object p = ref{:a} # reference to the variable :a q = a.ref # reference to the object in a r = ref{"a[4]"} # reference to the assignable expression a[4] s = a.ref[4] # reference to the [4] attribute of a t = a.ref.[](4) # same u = a.ref(:"[]",:"[]=",4) # same except set/get method names are explicit v = a.ref([:"[]",4],[:"[]=",4]) # same except arguments are explicit p[] # ["a", "b", "c", "d", "e", "f", "g", "h"] p[] = (0..7).to_a # [0, 1, 2, 3, 4, 5, 6, 7] a # [0, 1, 2, 3, 4, 5, 6, 7] b # ["a", "b", "c", "d", "e", "f", "g", "h"] q[] # ["a", "b", "c", "d", "e", "f", "g", "h"] q[] = (-7..0).to_a # [-7, -6, -5, -4, -3, -2, -1, 0] a # [0, 1, 2, 3, 4, 5, 6, 7] b # [-7, -6, -5, -4, -3, -2, -1, 0] r[] # 4 r[] = "r" # "r" a # [0, 1, 2, 3, "r", 5, 6, 7] b # [-7, -6, -5, -4, -3, -2, -1, 0] # extra arg is slice length s[2] # [-3, -2] s[2] = ["s"] # ["s"] a # [0, 1, 2, 3, "r", 5, 6, 7] b # [-7, -6, -5, -4, "s", -1, 0] t[] # "s" t[] = "t" # "t" a # [0, 1, 2, 3, "r", 5, 6, 7] b # [-7, -6, -5, -4, "t", -1, 0] u[] # "t" u[] = "t" # "u" a # [0, 1, 2, 3, "r", 5, 6, 7] b # [-7, -6, -5, -4, "u", -1, 0] v[] # "t" v[] = "t" # "v" a # [0, 1, 2, 3, "r", 5, 6, 7] b # [-7, -6, -5, -4, "v", -1, 0] # multiple ways to make a reference to lines in stdin/stdout lineref = Reference.new(method(:gets),method(:puts)) lineref = Reference.new(proc{gets},proc{|v|puts(v)}) line = lineref[] # line = gets lineref[]="hello world!" # puts("hello world!") Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html