From: Florian Gross Date: 2005-01-20T05:26:01+09:00 Subject: Re: value by reference Mark Hubbart wrote: >>do_something if ref # always done >>x = ref || y # x is always ref > > Ah, I hadn't thought of that. I guess if you would need to > de-reference in conditionals: > do_something if ref.__value__ Yup, #to_bool is really missing here. >>Some of Ruby's C methods want their arguments to be instances of a >>particular class. They won't even call the usual #to_x methods. >>str.scan(ref) is one example of that. > > I didn't know of that one. So String.scan doesn't use duck typing? Lots of C methods don't even try to convert their arguments which is quite sad. There's no #to_re or #to_regexp. Because of that I have to use a huge work-around in Regexp::English that involves sub classing Regexp and recalling the Regexp#initialize method whenever the value changes... >>Object.instance_method(:inspect).bind(ref).call calls the #inspect >>method of the ref, not of the Object it refers to. > > I would consider that a feature :) at a later time, a method could be > added, __ref__, would would allow you to call normal ruby methods on > the reference object; get its id, inspect it, etc. I agree, I'm even using the above when I don't trust the methods the Object provides. (Sandboxes, DRb) But it's still a case where the caller needs to be aware of refs and possibly dereference them manually.