Dave Burt
5/7/2005 3:35:00 AM
"Eric Mahurin" <eric_mahurin@yahoo.com> queried:
>> (ref.rb)
>I tried this out and it doesn't seem to do anything. I did a
> require "delegate" followed by the code below. Could you give
> a concrete example - working on mutable (string or array) and
> immediate obects (i.e. Fixnum). Even if you get this to work
> on the mutable objects, I don't see it working on the immediate
> objects.
# require 'ref'
irb(main):030:0> a = 1.ref
=> 1
irb(main):031:0> a.ref = 2 # []= is a synonym for ref=
=> 2
irb(main):032:0> a # here you can see the ref delegates inspect to the
number 2
=> 2
irb(main):033:0> a + 1 # and + is delegated too
=> 3
irb(main):034:0> a.class # class, kind_of?, is_a? and respond_to? aren't
=> Ref
irb(main):035:0> a.deref.class # [] is a synonym for deref
=> Fixnum
Maybe ref= should be called deref=. But there it is.
Cheers,
Dave