"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
Where do I get your ref.db? I saw a link in another post of
yours and it didn't work.
What does this do?
# silly example as x,y = y,x would be better
def swap(a,b)
tmp = a
a = b
b = tmp
end
x = 1
y = 2
swap(x.ref,y.ref)
p x
p y
x = "hi"
y = "world"
z = x
swap(x.ref,y.ref)
p x
p y
p z
If this doesn't work, I don't see the real use of the way you
did it. If on the other hand you use evil.rb/become or replace
to assign the dereferenced object, you could at least get the
second case to work (and other non-immediates). If it does
work, great. I want to know how the immediate case is handled.
For now, I'm using replace or become (if available to the
object) to accomplish the above dereferencing (to an object)
assignment. And I still have all the other types of references
(to a variable, assignable expression, attribute/member,
get/set methods, etc) in place. I need to document what I
have, package it into a gem and upload to rubyforge.
Maybe ref= should be called deref=. But there it is.
yes, this is a dereferencing modify. You are not modifying the
reference itself.
I really don't like the idea of your references looking like
the underlying object. This just confuses things. A reference
is a reference and you can get/set the object that it
references. If you want to get info about the object that it
references, just get it and query it by getting it from the
reference. Why muddy what the reference is?
···
--- Dave Burt <dave@burt.id.au> wrote:
__________________________________
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
http://mobile.yahoo.com/learn/mail