From: Eric Mahurin Date: 2005-05-07T01:29:05+09:00 Subject: Re: object reference handle (like perl's reference to scalar) Nope. You need a dereferencing operator/method just like C. Otherwise you'd be assigning to the reference itself rather than what it points to. Here would be the equivalents to C: C Ruby/ref ---- -------- p=&a p=ref{:a} *p p[] *p= p[]= You can reference/dereference just about anything with this ruby scheme instead of just a place in memory like you do in C. Actually, thinking about it more, I'm going to pull this reference API into another project I'm working on: "cursor". A Cursor is what some also call an "external iterator" (see Iterator on rubyforge), but mine is going to be more general. With this class, you'll be able to do this type of thing to correlate even more to the C pointer: C Ruby --------------- ----- int a[]={0,1,2} a=[0,1,2] # a is already a pointer in C int *p = a p = Cursor::Indexable(a) *p p[] *p= p[]= *(++p) p.succ![] *(++p)= p.succ![]= So, a Cursor is a Reference that you can move around in a data structure (anything sequential - even an IO). Just like you can move a pointer around in a data structure to reference/dereference different elements. I haven't made and uploaded a "reference" gem yet (or "cursor"). All I've done is reserved the name on rubyforge. Feel free to play around with what I previously posted and comment. p.s. my middle initial is W and I'm 6'2" > is it possible to remove the [] appendix? :-) > > something like, > > hacker = ["bot","pen","a",5,10] > > name = hacker.ref[0..2] > fname = name.ref[0] > lname = name.ref[1] > mname = name.ref[2] > > height = hacker.ref[3..4] > feet = height.ref[1] > inches = height.ref[2] > > fname = "Eric" > lname = "Mahurin" > mname = "?" > > feet = 6 > inches = 5 > > name #=> ["Eric","Mahurin","?"] > height #=> [6,5] > hacker #=> ["Eric","Mahurin","?",6,5] > > > Possible? > > btw, i cannot download your reference gem... > > thanks and kind regards -botp __________________________________ Do you Yahoo!? Yahoo! Mail - Helps protect you from nasty viruses. http://promotions.yahoo.com/new_mail