From: Eric Mahurin Date: 2005-08-30T23:10:16+09:00 Subject: Re: Method behaves differently when called using #send --- James Edward Gray II wrote: > On Aug 30, 2005, at 4:05 AM, Eric Mahurin wrote: > > > * For almost every case I use #send/#__send__, I use it to > > bypass encapsulation to call a protected/private method. > > Are you sure you've set the method's scope correctly in the > first > place then? To me, this sounds like a problem. Usually, I use it to access protected/private methods of core classes, not under my control. There have been a few cases where I use it to access a method that I don't want being used outside of my package but want access within the package. But, even for those cases I usually end up deciding to make them public, not documenting them, and prefixing the name with "_". > On the flip side, I'm pretty sure I've never used send() for > anything > but to call a method I didn't know the name of until runtime. > As you > noted, we already have instance_eval() for direct access. So you use #send for calling a variable method and #instance_eval for bypassing protection. I use #method/Method#call for calling a variable method (usually iteratively) and #send for bypassing protection. To me #send seems cleaner for bypassing protection because you don't need a block (and possible inefficiency that comes with it). I wonder what the general preferences are for bypassing method protection: #send vs. #instance_eval. ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs