From: Brian Palmer Date: 2004-12-30T14:52:53+09:00 Subject: Re: #send and private methods I certainly see what you mean--I can think of cases where it would be useful to bypass the private status of a method, as well. I was curious how others felt, though. The reason I ran across the #send behavior is this--I've been toying with different ways of writing a Infocom-style text adventure interpreter in Ruby, and one idea I had was a 'command' object or module that would contain a bunch of methods named after verbs, such as 'look' and 'west'. Then I would just have the interpreter do a #send with whatever the user typed in, and let #method_missing handle the "I don't understand what you mean" type messages. I was just a bit shocked when I discovered that typing 'gets' into my interpreter actually called the private method 'gets' (and I started thinking about what the adventurous adventurer could do with a well-designed #instance_eval command :) But of course, this is easily avoided by checking whether #send would call a public method, or using the awesome "evil ruby" to make a class without Object and Kernel methods. Not to mention that, while an interesting idea, it's not necessarily the most elegant way to do things anyway. Thanks for the feedback! - Brian Palmer David Heinemeier Hansson wrote: >> What's the rationale for having #send bypass the private status of a >> method? > > > That it's endlessly useful to be able to mindfully sidestep the rules > when the pressures are right. I use this to much delight in various > places in Rails where I'm well aware of the fact that the call is to a > private, but I choose to anyway. > > To me, that's the essence of Ruby. Guidance, not constraints. Make it > ugly instead of impossible. > > Three cheers for a send that sidesteps visibility ;)! > -- > David Heinemeier Hansson, > http://www.basecamphq.com/ -- Web-based Project Management > http://www.rubyonrails.org/ -- Web-application framework for Ruby > http://macromates.com/ -- TextMate: Code and markup editor (OS X) > http://www.loudthinking.com/ -- Broadcasting Brain > > > > >