From: Thomas Hurst Date: 2002-01-24T23:27:04+09:00 Subject: Re: Easy references in Ruby? * michael libby (x@ichimunki.com) wrote: > You don't really need a reference with Ruby's built-in aliasing do > you? I think the question is more along the lines of "how can I make talking about 'a' identical to talking about 'b', or '@foo', or something in a faraway scope". Yesterday I was trying to fill in the values for an object in a way that would warn about errors but let you continue, e.g; # make attrs a list of references to attributes attrs = [:@foo, :@bar, :@wibble] # values to convert vals = ['0212', 'foobar', '0523'] begin attr = attrs.shift attr = vals.shift.oct rescue ArgumentError puts "Failed converting a field." attr = nil retry end Which would fill in the object's attributes progressively, and would just skip fields that can't be converted This, of course, wasn't the way I actually did it; I had a scatchlist the values were pushed onto and then all the attributes were assigned afterwards from it, but it would have been nice to have been able to do it in-place. -- Thomas 'Freaky' Hurst - freaky@aagh.net - http://www.aagh.net/ - He who despises himself nevertheless esteems himself as a self-despiser. -- Friedrich Nietzsche