[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: object reference handle (like perl's reference to scalar

Peña, Botp

5/6/2005 7:46:00 AM

dave.burt@gmail.com [mailto:dave.burt@gmail.com] wrote:

#This is not possible, unfortunately.
#In Ruby,
# fname = "Eric"
#is just an assignment to a local variable. There are no method
#calls involved, and nothing to intercept.

Thanks for the enlightenment, dave. I was narrowly thinking on pure
object-oriented-ness..

#
#You can, of course, go even further and remove the =, leaving:
# fname "Eric"

i'm happy w =. It's more like a "replace" and clearer for me..

How about := ? (Remembering pascal...)

fname := "Eric"

It looks/means much better/clearer.

## Please add the following line to the top of ref.rb:
#require 'delegate'
#
## on with the example
#require 'ref'
#
#hacker = ["bot","pen","a",5,10].map{|x|x.ref}.ref
#
#name = hacker[0..2]
#fname = name[0]
#lname = name[1]
#mname = name[2]
#
#height = hacker[3..4]
#feet = height[0] # I corrected an off-by one here
#inches = height[1] # and here
#
#fname[] = "Eric" # or like this: fname.ref = "Eric"
#lname[] = "Mahurin"
#mname[] = "?"
#
#feet[] = 6
#inches[] = 5
#
#p name #=> ["Eric","Mahurin","?"]
#p height #=> [6,5]
#p hacker #=> ["Eric","Mahurin","?",6,5]
#

thanks.
btw, where can i get your delegate.rb?

thanks and kind regards -botp



1 Answer

Dave Burt

5/6/2005 3:45:00 PM

0

""Peña, Botp"" <botp@delmonte-phil.com> wrote:
> # fname = "Eric"
> #is just an assignment to a local variable. There are no method
> #calls involved, and nothing to intercept.
>
> Thanks for the enlightenment, dave. I was narrowly thinking on pure
> object-oriented-ness..

You're welcome.

> #You can, of course, go even further and remove the =, leaving:
> # fname "Eric"
>
> i'm happy w =. It's more like a "replace" and clearer for me..
>
> How about := ? (Remembering pascal...)
>
> fname := "Eric"
>
> It looks/means much better/clearer.
>

Ugh. Can't do that, either, but you can have this:
fname :=, "Eric"
where := is an ignored symbol literal, and "Eric" is the real value being
assigned. Works the same way as 'fname "Eric"'.

> btw, where can i get your delegate.rb?

It's not mine, it's in the standard library. require 'delegate' should just
work.

Cheers,
Dave