From: Brian Candler Date: 2009-02-24T18:57:54+09:00 Subject: Re: pointer and other questions Daniel Schoch wrote: > I just started with ruby and I understand from reading the documentation > that pointers don't exist. I'm in the process of writing a netlister. > Such a software is usually built using several linked lists. More > precisely, each element of one list contains a pointer to an element of > some other list. > So I was wondering how this can be achieved. In Ruby everything is a reference to an object, and you can think of a reference as a pointer to that object's representation in memory. There is an optimisation for Fixnum, nil, false and true which means that these don't actually allocate memory, because the value is buried within the reference itself, but from the outside they still behave the same: a = 3 puts a # 3 class Fixnum def double self + self end end puts a.double # 6 Note that Fixnum/true/false/nil are immutable. That is, you can't change the value of the object '3', but you can change your variable so that it holds a reference to some other object. a = 4 # a now points to a different Fixnum puts a # 4 For mutable objects, you end up with aliasing effects: a = "hello" b = a # pointer to same object a.upcase! puts a # "HELLO" puts b # "HELLO" The aliasing is the same as you'd get with char *a = strdup("hello"); char *b = a; HTH, Brian. -- Posted via http://www.ruby-forum.com/.