ruby picture

RCR 177: linking object : mapping on object from an other

Submitted by bille2 (Sun Dec 21 11:12:12 UTC 2003)

Abstract

  In C language, you can >>link<< 1 variable with another. Indeed something like *c = *p, so change p to p = 2, and c would also take 2 as value.

Problem

  I want some part of my ruby's object to be linked to existing ones from an other object

Proposal

So it would be nice if, for example :
   &c = &p 
  and p = 2 produce c = 2

Analysis

I think it would be simple ...

Implementation

An simple memory link, as in C, where *c and *p involve that c and p share the same memory portion !

  Many thanks for listening users !
ruby picture
Comments Current voting


Can I just say "no" to this proposal?

Because:

  • this proposal does not express the problem in detail.

  • besides, C does not have any variable aliasing, C++ does.

  • despite the observation in the proposal, the implementation would not be easy and simple at all. variables in Ruby is not implemented by memory links, but by binding in the table.

  • this change may cause unexpected side-effect.

So I demand you to come back with why you really need this.

matz.


This is a cross-cutting concern, so it is an AOP-type feature. You may consider a more robust solution. A thread on suby-muse recently introduced the idea of sharable namespaces. For example:


          
  namespace N
    attr_accessor :x
  end
class A share N end
class B share N end
a = A.new b = B.new
a.x = 5 b.x # => 5

If you would be interested in flushing this out more, and help in improving your RCR, please join at:

  http://lists.berlios.de/mailman/listinfo/suby-muse

The folks there are more than happy to discuss. ---


Strongly opposed 16
Opposed 1
Neutral 1
In favor 0
Strongly advocate 1
ruby picture
If you have registered at RCRchive, you may now sign in below. If you have not registered, you may sign up for a username and password. Registering enables you to submit new RCRs, and vote and leave comments on existing RCRs.
Your username:
Your password:

ruby picture

Powered by .