[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03847] RE: Private variables can be changed outside?

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-07-05 18:28:14 UTC
List: ruby-talk #3847
Let me add one more thing (I'm starting to feel Columbo ;).

> every class *can* access every 
> other's instance
> variables!
...
> 2) a method Class#spy, to the class we wanted to inspect, 
>    which calls just created Object#spy

Of course it's easier to spy by creating Class#spy like this:

class Foo
  def spy
    @var = send_and_alter( @var )
  end
end

But the trick is to mess up with object's variables without changing it or
letting it know in any way. 

If only we know any of the class' methods which calls any of Object's
methods, we could alter Object#called_method, intercept the message, peek
what out cute object has eaten today, call the aliased
Object#original_method and return it's value. The object didn't knew it was
fooled.

Even if I've not made any mistake here somewhere (quite unprobable :) and
such spying is possible, I don't think the hole this opens up is really big.
Or it might be, but I don't know *why* to use it. Anyway, the 'private' has
less power.

	- Aleksi

In This Thread

Prev Next