From: "David A. Black" Date: 2005-08-29T11:42:02+09:00 Subject: Re: Method behaves differently when called using #send Hi -- On Mon, 29 Aug 2005, Jeff Wood wrote: > Douglas Livingstone wrote: > >> On 8/29/05, Jeff Wood wrote: >> >>> It breaks encapsulation for anything to call a private method other than >>> the object itself... So, I guess it needs to have scope... >>> >>> >> >> We have open classes remember :) >> >> It isn't so much a problem that send/send! can break encapsulation, >> rather it is "when you want to break encapsulation, how do you want to >> do it?" >> >> Douglas >> >> >> > Yes but adding/taking away from an object doesn't change it's interaction > with the world... > > The engine of a car can be added to and taken away from ... it's an instance > ... but, that doesn't give the gas pedal control over the radiator... > > Encapsulation should be enforced... My vote is solidly against adding > anything that allows something outside of an object to have access to that > objects internal bits... bad juju. It's not being added, just refactored. Kernel#send already does this: irb(main):005:0> obj = Object.new => # irb(main):006:0> class << obj; private; def x; "hi"; end; end => nil irb(main):007:0> obj.x NoMethodError: private method `x' called for # from (irb):7 irb(main):008:0> obj.send(:x) => "hi" Matz wants to move this out of send to another method, so that send itself won't let you run private methods any more. But the ability to do so isn't new. (There's also instance_eval, with which you can do the same thing.) David -- David A. Black dblack@wobblini.net